From 2326c90fc38bb5d72d21fcd37ec9be87d265f070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halvor=20Grizzly=20Bj=C3=B8rn?= Date: Tue, 11 Jun 2024 10:20:28 +0200 Subject: [PATCH] =?UTF-8?q?:goal=5Fnet:=20Bedre=20h=C3=A5ndtering=20av=202?= =?UTF-8?q?04=20meldinger=20fra=20backend,=20slik=20at=20vi=20ikke=20trigg?= =?UTF-8?q?er=20migrering=20og=20validering=20av=20tomme=20mellomlagringer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/api/simpleTokenXProxy.ts | 2 +- pages/api/mellomlagring/les.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/utils/api/simpleTokenXProxy.ts b/lib/utils/api/simpleTokenXProxy.ts index 54ef4315..61654195 100644 --- a/lib/utils/api/simpleTokenXProxy.ts +++ b/lib/utils/api/simpleTokenXProxy.ts @@ -68,7 +68,7 @@ export const simpleTokenXProxy = async ({ logInfo(`OK ${url}, status ${response.status}, callId ${navCallId}`); if (response.status === 204) { - return {} as T; + throw new ErrorMedStatus('No content', response.status, navCallId); } const headers = response.headers.get('content-type'); diff --git a/pages/api/mellomlagring/les.ts b/pages/api/mellomlagring/les.ts index 7c2d951e..e6d7179a 100644 --- a/pages/api/mellomlagring/les.ts +++ b/pages/api/mellomlagring/les.ts @@ -1,14 +1,13 @@ import { NextApiRequest, NextApiResponse } from 'next'; -import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; -import { logError, logInfo, tokenXApiProxy } from '@navikt/aap-felles-utils'; -import metrics from 'utils/metrics'; +import { logError, logInfo } from '@navikt/aap-felles-utils'; import { lesCache } from 'mock/mellomlagringsCache'; import { isFunctionalTest, isMock } from 'utils/environments'; import { defaultStepList } from 'pages'; import { SOKNAD_VERSION, SoknadContextState } from 'context/soknadcontext/soknadContext'; import { simpleTokenXProxy } from 'lib/utils/api/simpleTokenXProxy'; import { IncomingMessage } from 'http'; +import { ErrorMedStatus } from 'lib/utils/api/ErrorMedStatus'; const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) => { const result = await hentMellomlagring(req); @@ -44,6 +43,12 @@ export const hentMellomlagring = async ( logInfo('Mellomlagret søknad hentet fra aap-innsending', mellomlagretSøknad); return mellomlagretSøknad; } catch (error: any) { + if (error instanceof ErrorMedStatus) { + if (error.status === 204) { + logInfo('Ingen mellomlagring funnet i aap-innsending'); + return undefined; + } + } logError('Noe gikk galt i henting av mellomlagring fra aap-innsending', error); return undefined; }