Last active
December 29, 2015 05:09
-
-
Save maxkramer/7619326 to your computer and use it in GitHub Desktop.
All screenshots and no gists makes James unhappy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var renderError = function(res, error) { | |
res.status = 404; | |
res.render('error', { | |
title: 'Error', | |
error: error | |
}); | |
}; | |
exports.findWithId = function(req, res) { | |
var Article = mongoose.model('Article'); | |
Article.findById(req.params['id'], function(err, article) { | |
console.log(err + " " + article); | |
if (err) { | |
renderError(res, err.message); | |
} | |
else { | |
if (article == undefined || article == null) { | |
renderError(res, "No article with id " + req.params["id"] + " exists."); | |
} | |
else { | |
renderSuccess(res, article); | |
} | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Arrggh, had a huge comment but fucking
Preview
button did something weird and deleted my commentsin short, you should specify some error handler function as mentioned here :: http://expressjs.com/guide.html#error-handling
and then in your function just call next(err) with some error message