From 4d7bfc94cd2dcae362613b5b149c8b8a59a69f56 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Wed, 29 Jul 2015 10:21:47 -0700 Subject: [PATCH] Fix error handling --- lib/dao.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index 9cc3e530..d69ae93e 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -1382,7 +1382,7 @@ DataAccessObject.find = function find(query, options, cb) { var allCb = function(err, data) { var results = []; - if (Array.isArray(data)) { + if (!err && Array.isArray(data)) { async.each(data, function(item, callback) { var d = item;//data[i]; var Model = self.lookupModel(d); @@ -1434,7 +1434,7 @@ DataAccessObject.find = function find(query, options, cb) { callback(); }); } - }, + }, function(err) { if (err) return cb(err); @@ -1448,8 +1448,9 @@ DataAccessObject.find = function find(query, options, cb) { cb(err, results); }); } - else - cb(err, []); + else { + cb(err, data || []); + } }; if (options.notify === false) { @@ -2370,7 +2371,7 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, op return; } else if (strict === 'validate') { inst.__unknownProperties.push(key); - } + } } data = removeUndefined(result); }