Subd/server/middleware/error-handling.middleware.ts
2024-04-23 12:08:46 +04:00

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: "Непредвиденная ошибка"})
}