Skip to content

Commit

Permalink
🥅 Bedre håndtering av 204 meldinger fra backend, slik at vi ikke trig…
Browse files Browse the repository at this point in the history
…ger migrering og validering av tomme mellomlagringer
  • Loading branch information
mrbjoern authored Jun 11, 2024
2 parents ed9ab53 + 2326c90 commit b41e785
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/utils/api/simpleTokenXProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const simpleTokenXProxy = async <T>({
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');
Expand Down
11 changes: 8 additions & 3 deletions pages/api/mellomlagring/les.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit b41e785

Please sign in to comment.