Spaces:
Running
Running
Download src/exception/globalExceptionHandler.js from hari7775/resume-server: direct link, hf CLI and curl.
- Browser
- Download file 897 Bytes
-
https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/exception/globalExceptionHandler.js
- Command line
-
hf download hf://spaces/hari7775/resume-server/src/exception/globalExceptionHandler.js
-
curl -L -o globalExceptionHandler.js https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/exception/globalExceptionHandler.js
897 Bytes
| import { AppError } from './errors.js'; | |
| // Lets controllers be plain async functions: a thrown error or rejected promise reaches errorHandler | |
| export const asyncHandler = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next); | |
| // Registered last in index.js | |
| export function errorHandler(err, req, res, next) { | |
| if (res.headersSent) return next(err); | |
| if (err instanceof AppError) { | |
| return res.status(err.status).json({ error: err.code, message: err.message }); | |
| } | |
| // express.json() payload problems (too large, malformed JSON) carry their own 4xx status | |
| if (err.status >= 400 && err.status < 500) { | |
| return res.status(err.status).json({ error: 'BAD_REQUEST', message: err.message }); | |
| } | |
| console.error('[Unhandled Error]', err); | |
| res.status(500).json({ error: 'INTERNAL_ERROR', message: 'Something went wrong on the server.' }); | |
| } | |