Skip to content

Commit

Permalink
next-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehansen2 committed Nov 24, 2023
1 parent d84e935 commit e98bc68
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/dine-pleiepenger/src/pages/api/soker.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { Søker } from '../../types/Søker';
import { isForbidden } from '../../utils/apiUtils';
import { getSøker } from '../../server/innsynService';
import { isLocal } from '../../utils/env';
import { createChildLogger } from '@navikt/next-logger';

async function handler(req: NextApiRequest, res: NextApiResponse) {
const childLogger = createChildLogger(req.headers['x-request-id'] as string);

try {
const context = !isLocal
? createRequestContext(req.headers['x-request-id'] as string | undefined, req.headers['authorization'])
Expand All @@ -16,9 +19,12 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
res.status(401).json({ error: 'Access denied - context is undefined' });
return;
}
childLogger.debug(context);
const response = await getSøker(context);
res.send(response);
} catch (err) {
childLogger.error(`Fetching søker failed: ${err}`);
childLogger.debug(err);
if (isForbidden(err)) {
res.status(403).json({ error: 'Bruker har ikke tilgang' });
}
Expand Down

0 comments on commit e98bc68

Please sign in to comment.