hw6: 400 on mongoose errors
This commit is contained in:
parent
6e78f24bdd
commit
eedf00fdcc
1 changed files with 2 additions and 1 deletions
|
@ -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) }),
|
||||||
|
|
Reference in a new issue