diff --git a/lib/model.js b/lib/model.js index 90e3dbea..d93e4ab4 100644 --- a/lib/model.js +++ b/lib/model.js @@ -677,7 +677,7 @@ Model.nestRemoting = function(relationName, options, cb) { try { nestedFn.apply(inst, args); } catch (err) { - cb && cb(err); + if (cb) return cb(err); } } else if (cb) { cb(err, null); @@ -695,7 +695,7 @@ Model.nestRemoting = function(relationName, options, cb) { try { nestedFn.apply(inst, args); } catch (err) { - cb && cb(err); + if (cb) return cb(err); } } else if (cb) { cb(err, null); diff --git a/test/relations.integration.js b/test/relations.integration.js index 21a54d9b..f1aa72da 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -1169,7 +1169,7 @@ describe('relations - integration', function() { Image.belongsTo(Book); // fake a remote method that match the filter in Model.nestRemoting() - Page.prototype.__throw__errors = function () { + Page.prototype['__throw__errors'] = function() { throw new Error('This should not crash the app'); }; @@ -1313,7 +1313,7 @@ describe('relations - integration', function() { }); }); - it('should catch error if nested function throws', function (done) { + it('should catch error if nested function throws', function(done) { var test = this; this.get('/api/books/' + test.book.id + '/pages/' + this.page.id + '/throws') .end(function(err, res) {