Skip to content

Commit

Permalink
Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbjoern committed Mar 13, 2024
1 parent 77138d8 commit 9fca943
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
9 changes: 4 additions & 5 deletions pages/api/mellomlagring/lagre.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { getAccessTokenFromRequest } from 'auth/accessToken';
import { beskyttetApi } from 'auth/beskyttetApi';
import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils';
import { logError, logInfo } from '@navikt/aap-felles-utils';
import { lagreCache } from 'mock/mellomlagringsCache';
import { isFunctionalTest, isMock } from 'utils/environments';
import metrics from 'utils/metrics';

import { StepType } from 'components/StepWizard/Step';
import { hentMellomlagring } from 'pages/api/mellomlagring/les';
Expand Down Expand Up @@ -35,14 +33,15 @@ export const mellomlagreSøknad = async (data: object, req: IncomingMessage) =>
if (isFunctionalTest()) return;
if (isMock()) return await lagreCache(JSON.stringify(data));
try {
await simpleTokenXProxy({
const result = await simpleTokenXProxy({
url: `${process.env.INNSENDING_URL}/mellomlagring/søknad`,
method: 'POST',
audience: process.env.INNSENDING_AUDIENCE!,
body: data,
req,
});
return;
logInfo('Søknad lagret via aap-innsending', result);
return result;
} catch (error) {
logError('Noe gikk galt ved mellomlagring av søknad', error);
throw new Error('Error saving søknad via aap-innsending');
Expand Down
4 changes: 2 additions & 2 deletions pages/api/mellomlagring/les.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { getAccessTokenFromRequest } from 'auth/accessToken';
import { beskyttetApi } from 'auth/beskyttetApi';
import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils';
import { logError, logInfo, tokenXApiProxy } from '@navikt/aap-felles-utils';
import metrics from 'utils/metrics';
import { lesCache } from 'mock/mellomlagringsCache';
import { isFunctionalTest, isMock } from 'utils/environments';
Expand Down Expand Up @@ -37,7 +37,7 @@ export const hentMellomlagring = async (
audience: process.env.INNSENDING_AUDIENCE!,
req,
});

logInfo('Mellomlagret søknad hentet fra aap-innsending', mellomlagretSøknad);
return mellomlagretSøknad;
} catch (error: any) {
logError('Noe gikk galt i henting av mellomlagring fra aap-innsending', error);
Expand Down
7 changes: 4 additions & 3 deletions pages/api/mellomlagring/slett.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { getAccessTokenFromRequest } from 'auth/accessToken';
import { beskyttetApi } from 'auth/beskyttetApi';
import { logError, tokenXApiProxy } from '@navikt/aap-felles-utils';
import { logError, logInfo, tokenXApiProxy } from '@navikt/aap-felles-utils';
import metrics from 'utils/metrics';
import { deleteCache } from 'mock/mellomlagringsCache';
import { isMock } from 'utils/environments';
Expand All @@ -21,13 +21,14 @@ export const slettBucket = async (req: IncomingMessage) => {
}

try {
await simpleTokenXProxy({
const result = await simpleTokenXProxy({
url: `${process.env.INNSENDING_URL}/mellomlagring/søknad`,
method: 'DELETE',
audience: process.env.INNSENDING_AUDIENCE!,
req,
});
return;
logInfo('Søknad slettet via aap-innsending', result);
return result;
} catch (error) {
logError('Noe gikk galt ved sletting av søknad', error);
throw new Error('Error deleting søknad via aap-innsending');
Expand Down

0 comments on commit 9fca943

Please sign in to comment.