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

18 lines
527 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";
if (err instanceof CustomRequestException) {
status = err.statusCode;
msg = err.message;
}
2024-09-09 11:14:24 +00:00
console.log("Handler", err);
res.status(status).send(msg);
}