Spaces:
Running
Running
Download src/middleware/errorHandler.js from AndreaNotes1/auth-app-api: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/AndreaNotes1/auth-app-api/resolve/main/src/middleware/errorHandler.js
- Command line
-
hf download hf://spaces/AndreaNotes1/auth-app-api/src/middleware/errorHandler.js
-
curl -L -o errorHandler.js https://huggingface.co/spaces/AndreaNotes1/auth-app-api/resolve/main/src/middleware/errorHandler.js
1.01 kB
| const logger = require("../utils/logger"); | |
| // eslint-disable-next-line no-unused-vars | |
| function errorHandler(err, req, res, next) { | |
| let status = err.status || 500; | |
| // Multer surfaces file-size/type problems as plain Errors/MulterErrors | |
| // without a status code — treat those as client errors (400), not | |
| // server failures. | |
| if (err.name === "MulterError" || /Unsupported file type/.test(err.message || "")) { | |
| status = 400; | |
| } | |
| logger.error("Unhandled error", { | |
| message: err.message, | |
| status, | |
| path: req.path, | |
| method: req.method, | |
| // stack only ever goes to server-side logs, never to the client | |
| stack: err.stack, | |
| }); | |
| const isProd = process.env.NODE_ENV === "production"; | |
| res.status(status).json({ | |
| error: status === 500 && isProd ? "Something went wrong. Please try again later." : err.message, | |
| }); | |
| } | |
| function notFound(req, res) { | |
| res.status(404).json({ error: "Not found." }); | |
| } | |
| module.exports = { errorHandler, notFound }; | |