Subd/server/middleware/error-handling.middleware.ts

10 lines
421 B
TypeScript
Raw Permalink Normal View History

2024-04-23 12:08:46 +04:00
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: "Непредвиденная ошибка"})
}