feat(backend): Eigen error handler toegevoegd.
Hiervoor was ook refactoring aan de exception-klassen nodig.
This commit is contained in:
parent
bc94b25a6a
commit
aaa71aa648
14 changed files with 103 additions and 55 deletions
|
@ -6,7 +6,8 @@ import * as express from 'express';
|
|||
import * as jwt from 'jsonwebtoken';
|
||||
import { AuthenticatedRequest } from './authenticated-request.js';
|
||||
import { AuthenticationInfo } from './authentication-info.js';
|
||||
import { ForbiddenException, UnauthorizedException } from '../../exceptions.js';
|
||||
import {UnauthorizedException} from "../../exceptions/unauthorized-exception";
|
||||
import {ForbiddenException} from "../../exceptions/forbidden-exception";
|
||||
|
||||
const JWKS_CACHE = true;
|
||||
const JWKS_RATE_LIMIT = true;
|
||||
|
|
15
backend/src/middleware/error-handling/error-handler.ts
Normal file
15
backend/src/middleware/error-handling/error-handler.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import {NextFunction, Request, Response} from "express";
|
||||
import {getLogger, Logger} from "../../logging/initalize";
|
||||
import {ExceptionWithHttpState} from "../../exceptions/exception-with-http-state";
|
||||
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
export function errorHandler(err: unknown, req: Request, res: Response, _: NextFunction): void {
|
||||
if (err instanceof ExceptionWithHttpState) {
|
||||
logger.warn(`An error occurred while handling request ${JSON.stringify(req)}: ${err.error} (-> HTTP ${err.status})`);
|
||||
res.status(err.status).json(err);
|
||||
} else {
|
||||
logger.error(`Unexpected error occurred while handling request ${JSON.stringify(req)}: ${JSON.stringify(err)}`);
|
||||
res.status(500).json(err);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue