PIbd-23_Dyakonov_R_R_SUBD_P.../server/middleware/error-handling.middleware.ts

10 lines
421 B
TypeScript

import { NextFunction, Request, Response } from "express"
import { ApiErrorHandler } from "../error/api-error.handler.ts"
export function ErrorHandlingMiddleware(err: Error, req: Request, res: Response, next: NextFunction) {
if (err instanceof ApiErrorHandler) {
return res.status(err.status).json({message: err.message})
}
return res.status(500).json({message: "Непредвиденная ошибка"})
}