From d9046cccc7a3b380f620c3ea27213abb2e223bd9 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Sat, 9 Nov 2013 20:33:43 +0000 Subject: [PATCH] update: Throw error if there is one Beforehand, if there was no entity but there was an error, that error would not be propagated (via the callback). --- lib/mongodb-engine.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/mongodb-engine.js b/lib/mongodb-engine.js index 9a245ac..7e60f36 100644 --- a/lib/mongodb-engine.js +++ b/lib/mongodb-engine.js @@ -102,6 +102,10 @@ module.exports = function (collection, engineOptions) { delete updateObject[options.idProperty] collection.findAndModify(castIdProperty(query), [['_id', 'asc']], updateData, { 'new': true }, function (error, entity) { + + if (error) { + return callback(error) + } if (!entity) { callback(new Error('No object found with \'' + options.idProperty + @@ -109,7 +113,7 @@ module.exports = function (collection, engineOptions) { } else { entity = objectIdToString(entity) self.emit('afterUpdate', entity) - callback(error, entity) + callback(null, entity) } }) } @@ -225,4 +229,4 @@ module.exports = function (collection, engineOptions) { , idProperty: options.idProperty , idType: ObjectID }) -} \ No newline at end of file +}