fixing issue #348 - instead of returning a server error 500 on article loading which isnt found we'll throw a 404 with json message

This commit is contained in:
Liran Tal
2015-01-09 11:06:17 +02:00
parent bde2412e2a
commit 56aff70dfd

View File

@@ -89,7 +89,11 @@ exports.list = function(req, res) {
*/
exports.articleByID = function(req, res, next, id) {
Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
if (err) return next(err);
if (err) {
return res.status(404).send({
message: 'Article not found'
});
}
if (!article) return next(new Error('Failed to load article ' + id));
req.article = article;
next();