From 5c07c113009f9bc8d565d8283e612b7cb3e13dc8 Mon Sep 17 00:00:00 2001 From: EIlif Johansen Date: Sun, 19 Jan 2025 14:00:31 +0100 Subject: [PATCH] Fikset error melding --- app/api/create/route.ts | 20 ++++++++++---------- app/components/crud/create.tsx | 2 +- app/components/crud/delete.tsx | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/api/create/route.ts b/app/api/create/route.ts index 6cf0d21..59d7cb5 100644 --- a/app/api/create/route.ts +++ b/app/api/create/route.ts @@ -11,17 +11,17 @@ export async function POST(request: Request) { if (process.env.NODE_ENV === 'production') { token = getToken(request); if (!token) { - return NextResponse.json({ error: 'Missing token' }, { status: 401 }); + return NextResponse.json({ detail: 'Mangler token' }, { status: 401 }); } const validation = await validateToken(token); if (!validation.ok) { - return NextResponse.json({ error: 'Token validation failed' }, { status: 401 }); + return NextResponse.json({ detail: 'Token validering feilet' }, { status: 401 }); } const obo = await requestOboToken(token, 'api://prod-gcp.team-researchops.skup-backend/.default'); if (!obo.ok) { - return NextResponse.json({ error: 'OBO token request failed' }, { status: 401 }); + return NextResponse.json({ detail: 'OBO token forespørsel feilet' }, { status: 401 }); } token = obo.token; @@ -40,20 +40,20 @@ export async function POST(request: Request) { }); if (!response.ok) { - const errorDetails = await response.text(); - console.error('Network response was not ok:', response.status, errorDetails); - throw new Error(`Network response was not ok: ${response.status} - ${errorDetails}`); + const errorDetails = await response.json(); + console.error('Nettverksresponsen var ikke ok:', response.status, errorDetails); + return NextResponse.json({ detail: errorDetails.detail || `Nettverksresponsen var ikke ok: ${response.status}` }, { status: response.status }); } const data = await response.json(); return NextResponse.json(data); } catch (error) { if (error instanceof Error) { - console.error('Fetch failed:', error.message, error.stack); - return NextResponse.json({ error: 'Fetch failed', message: error.message, stack: error.stack }, { status: 500 }); + console.error('Henting feilet:', error.message, error.stack); + return NextResponse.json({ detail: 'Henting feilet' }, { status: 500 }); } else { - console.error('An unknown error occurred'); - return NextResponse.json({ error: 'An unknown error occurred' }, { status: 500 }); + console.error('En ukjent feil oppstod'); + return NextResponse.json({ detail: 'En ukjent feil oppstod' }, { status: 500 }); } } } \ No newline at end of file diff --git a/app/components/crud/create.tsx b/app/components/crud/create.tsx index 935bfef..76a813a 100644 --- a/app/components/crud/create.tsx +++ b/app/components/crud/create.tsx @@ -67,7 +67,7 @@ export default function CreateApp({ onAppCreated }: { onAppCreated: () => void } )} {error && ( - Uff, fikk ikke lagt til appen: {error} + {error} )} diff --git a/app/components/crud/delete.tsx b/app/components/crud/delete.tsx index 7ef3dca..44595c7 100644 --- a/app/components/crud/delete.tsx +++ b/app/components/crud/delete.tsx @@ -107,7 +107,7 @@ export default function DeleteApp({ onAppDeleted }: { onAppDeleted: () => void } )} {error && ( - Uff, fikk ikke slettet appen: {error} + {error} )}