Download apps/server/src/middleware/json-errors.ts from Leon4gr45/automaker: direct link, hf CLI and curl.
- Browser
- Download file 699 Bytes
-
https://huggingface.co/spaces/Leon4gr45/automaker/resolve/main/apps/server/src/middleware/json-errors.ts
- Command line
-
hf download hf://spaces/Leon4gr45/automaker/apps/server/src/middleware/json-errors.ts
-
curl -L -o json-errors.ts https://huggingface.co/spaces/Leon4gr45/automaker/resolve/main/apps/server/src/middleware/json-errors.ts
699 Bytes
| import type { ErrorRequestHandler } from 'express'; | |
| /** Never echo body-parser's body, stack, message, or filesystem details. */ | |
| export const jsonParserErrorHandler: ErrorRequestHandler = (error, _req, res, next) => { | |
| if (error?.type === 'entity.parse.failed' && error.status === 400) { | |
| res.status(400).json({ | |
| success: false, | |
| error: { code: 'MALFORMED_JSON', message: 'Invalid JSON payload received' }, | |
| }); | |
| return; | |
| } | |
| if (error?.type === 'entity.too.large' && error.status === 413) { | |
| res.status(413).json({ | |
| success: false, | |
| error: { code: 'PAYLOAD_TOO_LARGE', message: 'JSON payload exceeds the request limit' }, | |
| }); | |
| return; | |
| } | |
| next(error); | |
| }; | |