feat(backend): Eigen error handler toegevoegd.

Hiervoor was ook refactoring aan de exception-klassen nodig.
This commit is contained in:
Gerald Schmittinger 2025-03-30 12:25:41 +02:00
parent bc94b25a6a
commit aaa71aa648
14 changed files with 103 additions and 55 deletions

View 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);
}
}