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