hw6: 400 on mongoose errors

This commit is contained in:
Claudio Maggioni 2019-10-29 11:49:56 +01:00
parent 6e78f24bdd
commit eedf00fdcc
1 changed files with 2 additions and 1 deletions

View File

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