Spaces:
Sleeping
Sleeping
Download backend/src/middleware/errorHandler.ts from moustafa7/protofolio: direct link, hf CLI and curl.
- Browser
- Download file 827 Bytes
-
https://huggingface.co/spaces/moustafa7/protofolio/resolve/main/backend/src/middleware/errorHandler.ts
- Command line
-
hf download hf://spaces/moustafa7/protofolio/backend/src/middleware/errorHandler.ts
-
curl -L -o errorHandler.ts https://huggingface.co/spaces/moustafa7/protofolio/resolve/main/backend/src/middleware/errorHandler.ts
827 Bytes
| import { Request, Response, NextFunction } from "express"; | |
| import { AppError } from "../utils/AppError"; | |
| import { createChildLogger } from "../config/logger"; | |
| const log = createChildLogger({ module: "error" }); | |
| export const errorHandler = (err: Error, req: Request, res: Response, _next: NextFunction) => { | |
| if (err instanceof AppError) { | |
| log.warn(`${err.message}`, { statusCode: err.statusCode, url: req.originalUrl }); | |
| return res.status(err.statusCode).json({ | |
| success: false, | |
| message: err.message, | |
| }); | |
| } | |
| log.error("Unhandled error", { | |
| message: err.message, | |
| stack: err.stack, | |
| url: req.originalUrl, | |
| method: req.method, | |
| }); | |
| return res.status(500).json({ | |
| success: false, | |
| message: process.env.NODE_ENV === "production" ? "Internal Server Error" : err.message, | |
| }); | |
| }; | |