From eedf00fdcc8dec558d3889ffbb55839bf54dc6e8 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Tue, 29 Oct 2019 11:49:56 +0100 Subject: [PATCH] hw6: 400 on mongoose errors --- hw6/Claudio_Maggioni/routes/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) }),