import { NextFunction, Request, Response } from 'express'; import {HttpException} from './HttpError'; import { LogService } from './services/log.service'; import { Severity } from './entities/log.entity'; const ILLEGAL = [ 401, 403 ] async function errorMiddleware(error: HttpException, request: Request, response: Response, next: NextFunction) { const status = error.status || 500; const message = error.message || 'Something went wrong'; await LogService.getService().write({subject: null, message:`${status}: ${message}`, severity: ILLEGAL.includes(status)?Severity.ILLEGAL:Severity.ERROR}) response .status(status) .send({ status, message, }) } export default errorMiddleware;