Skip to content

Commit

Permalink
prevent app crash when document doesn't exist
Browse files Browse the repository at this point in the history
correctly return 404 instead
  • Loading branch information
oori committed Oct 12, 2012
1 parent c34f179 commit 91c9686
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = function MongooseRestRouter(base, router, options) {
router.put(base + '/:type/:id', function (req, res, next) {
var id = req.param('id');
m(req).findOne(idObj(req), function (err, obj) {
if (err)return next(err);
if (err || doc==null) return next(err);
_u.extend(obj, clean(req.body));
obj.save(function (err, ret) {
if (err) return next(err);
Expand All @@ -133,7 +133,7 @@ module.exports = function MongooseRestRouter(base, router, options) {
}

M.findOne(idObj(req), function(err, doc){
if (err) return next(err);
if (err || doc==null) return next(err);
doc.remove(send);
});

Expand Down

0 comments on commit 91c9686

Please sign in to comment.