diff --git a/hw6/Claudio_Maggioni/routes/utils.js b/hw6/Claudio_Maggioni/routes/utils.js index 215c1d7..0225b51 100644 --- a/hw6/Claudio_Maggioni/routes/utils.js +++ b/hw6/Claudio_Maggioni/routes/utils.js @@ -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) }),