Closed j-d-carmichael closed 5 years ago
As some what of a dirty hack, but dictating the status code feels like it should be done in the "errors" middleware:
export default () => {
return (err, req, res, next) => {
if (err.joi) {
res.status(422).json(err)
} else {
next(err)
}
}
}
@johndcarmichael please check https://github.com/arb/celebrate#errors and https://github.com/arb/celebrate#iscelebrateerr about celebrate
errors and the common use for isCelebrate
.
Basically, write your own celebrate
error handler and check isCelebrate(err)
to determine if the error came from a celebrate
validation failure.
node
version - 10 ltscelebrate
version - 10.0.0joi
version (vianpm ls --depth=0 | grep joi
) - not importantI am writing a collection of micro services that will work in combination with a few others, not all written in node. I need to align the error status code with the rest of the services, to http status code 422. This package is nice and simple but how can i acheive this, cannot see anything in the readme on changing it from 400.