Spaces:
Sleeping
Sleeping
Download server/src/middleware/errorHandler.ts from rohanchand21/freellmapi: direct link, hf CLI and curl.
- Browser
- Download file 411 Bytes
-
https://huggingface.co/spaces/rohanchand21/freellmapi/resolve/main/server/src/middleware/errorHandler.ts
- Command line
-
hf download hf://spaces/rohanchand21/freellmapi/server/src/middleware/errorHandler.ts
-
curl -L -o errorHandler.ts https://huggingface.co/spaces/rohanchand21/freellmapi/resolve/main/server/src/middleware/errorHandler.ts
411 Bytes
| import type { Request, Response, NextFunction } from 'express'; | |
| export function errorHandler(err: Error, _req: Request, res: Response, next: NextFunction) { | |
| console.error('[Error]', err.message); | |
| if (res.headersSent) return next(err); | |
| const status = (err as any).status ?? 500; | |
| res.status(status).json({ | |
| error: { | |
| message: err.message, | |
| type: err.name ?? 'server_error', | |
| }, | |
| }); | |
| } | |