Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🥅 Bedre håndtering av 204 meldinger fra backend, slik at vi ikke trigger migrering og validering av tomme mellomlagringer #156

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading