Spaces:
Runtime error
Runtime error
Download src/middleware/errorHandler.js from yeshwanth-kr/dss-server: direct link, hf CLI and curl.
- Browser
- Download file 769 Bytes
-
https://huggingface.co/spaces/yeshwanth-kr/dss-server/resolve/main/src/middleware/errorHandler.js
- Command line
-
hf download hf://spaces/yeshwanth-kr/dss-server/src/middleware/errorHandler.js
-
curl -L -o errorHandler.js https://huggingface.co/spaces/yeshwanth-kr/dss-server/resolve/main/src/middleware/errorHandler.js
769 Bytes
| function errorHandler(err, _req, res, _next) { | |
| if (err?.name === 'ValidationError') { | |
| const firstError = Object.values(err.errors || {})[0]; | |
| return res.status(400).json({ message: firstError?.message || 'Validation failed' }); | |
| } | |
| if (err?.name === 'CastError') { | |
| return res.status(400).json({ message: 'Invalid identifier' }); | |
| } | |
| if (err?.code === 11000) { | |
| const duplicateKeys = err.keyPattern || err.keyValue || {}; | |
| const field = Object.keys(duplicateKeys)[0] || 'field'; | |
| return res.status(409).json({ message: `${field} already exists` }); | |
| } | |
| if (err?.message) { | |
| return res.status(400).json({ message: err.message }); | |
| } | |
| return res.status(500).json({ message: 'Internal server error' }); | |
| } | |
| module.exports = errorHandler; | |