Skip to content

Commit

Permalink
BE #4 fix 404 on delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
tito433 committed May 17, 2020
1 parent ef80d6e commit 8d2590d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions routes/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,17 @@ router.route('/:articleId')
if (mongoose.Types.ObjectId.isValid(req.params.articleId)) {
Article.findByIdAndRemove(req.params.articleId)
.then((resp) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.json(resp);
if(null===resp){
var err = new Error('Article ' + req.params.articleId + ' not found');
err.status = 404;
return next(err);
}
else{
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.json(resp);
}

}, (err) => next(err))
.catch((err) => next(err));
}
Expand Down

0 comments on commit 8d2590d

Please sign in to comment.