ff-admin-server/src/middleware/errorHandler.ts

20 lines
598 B
TypeScript
Raw Normal View History

import { Request, Response } from "express";
import { ExceptionBase } from "../exceptions/exceptionsBaseType";
2024-08-23 07:44:36 +00:00
import CustomRequestException from "../exceptions/customRequestException";
2024-08-23 07:44:36 +00:00
export default function errorHandler(err: ExceptionBase | Error, req: Request, res: Response, next: Function) {
let status = 500;
let msg = "Internal Server Error";
2024-09-06 08:08:19 +00:00
let insideError = undefined;
2024-08-23 07:44:36 +00:00
if (err instanceof CustomRequestException) {
status = err.statusCode;
msg = err.message;
2024-09-06 08:08:19 +00:00
insideError = err.err;
2024-08-23 07:44:36 +00:00
}
2024-09-06 08:08:19 +00:00
console.log("Handler", err, insideError);
res.status(status).send(msg);
}