hw6: 400 on mongoose errors

This commit is contained in:
Claudio Maggioni 2019-10-29 11:49:56 +01:00
parent 6e78f24bdd
commit eedf00fdcc

View file

@ -8,7 +8,8 @@ function catchErrs(promise, res) {
function error(err, res) { function error(err, res) {
console.error(err); console.error(err);
res.status = 500; res.status = err instanceof mongoose.CastError ||
err instanceof mongoose.TypeError ? 400 : 500;
res.format({ res.format({
json: () => res.json({ error: err }), json: () => res.json({ error: err }),
html: () => res.render('500.dust', { err: JSON.stringify(err, null, 2) }), html: () => res.render('500.dust', { err: JSON.stringify(err, null, 2) }),