Added a comment to app.js about default express error handler behaviour.

This commit is contained in:
Martin Šošić 2023-09-06 17:18:21 +02:00 committed by GitHub
parent d30fd1cfb2
commit 7da0aae3e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,14 @@ app.use((err, _req, res, next) => {
return res.status(err.statusCode).json({ message: err.message, data: err.data })
}
// This forwards the error to the default express error handler.
// As described by expressjs documentation, the default error handler sets response status
// to err.status or err.statusCode if it is 4xx or 5xx, and if not, sets it to 500.
// It won't add any more info to it if server is running in production, which is exactly what we want,
// we want to share as little info as possible when error happens in production, for security reasons,
// so they will get only status code if set, or 500 if not, no extra info.
// In development it will also share the error stack though, which is useful.
// If the user wants to put more information about the error into the response, they should use HttpError.
return next(err)
})