Merge branch 'dev' into refactor/linting
This commit is contained in:
commit
588c556949
37 changed files with 686 additions and 796 deletions
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.js';
|
||||
import { ExceptionWithHttpState } from '../../exceptions/exception-with-http-state.js';
|
||||
|
||||
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 a request: ${err} (-> HTTP ${err.status})`);
|
||||
res.status(err.status).json(err);
|
||||
} else {
|
||||
logger.error(`Unexpected error occurred while handing a request: ${JSON.stringify(err)}`);
|
||||
res.status(500).json(err);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue