fix: properly propagate errors to the machine
This commit is contained in:
parent
8a9fb1d497
commit
801e7e54ff
1 changed files with 3 additions and 2 deletions
|
|
@ -1,13 +1,14 @@
|
|||
const logger = require('../logger')
|
||||
|
||||
function errorHandler(err, req, res) {
|
||||
function errorHandler(err, req, res, next) {
|
||||
const statusCode = err.name === 'HTTPError' ? err.code || 500 : 500
|
||||
|
||||
const json = { error: err.message }
|
||||
|
||||
if (statusCode >= 400) logger.error(err)
|
||||
|
||||
return res.status(statusCode).json(json)
|
||||
res.status(statusCode).json(json)
|
||||
next(err)
|
||||
}
|
||||
|
||||
module.exports = errorHandler
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue