diff --git a/lib/model.js b/lib/model.js index 1ab0bcaad29..7af6cc744a9 100644 --- a/lib/model.js +++ b/lib/model.js @@ -34,7 +34,7 @@ var VERSION_WHERE = 1, * * @param {Object} doc values with which to create the document * @inherits Document http://mongoosejs.com/docs/api.html#document-js - * @event `error`: If listening to this event, it is emitted when a document was saved without passing a callback and an `error` occurred. If not listening, the event bubbles to the connection used to create this Model. + * @event `error`: If listening to this event, 'error' is emitted when a document was saved without passing a callback and an `error` occurred. If not listening, the event bubbles to the connection used to create this Model. * @event `index`: Emitted after `Model#ensureIndexes` completes. If an error occurred it is passed with the event. * @event `index-single-start`: Emitted when an individual index starts within `Model#ensureIndexes`. The fields and options being used to build the index are also passed with the event. * @event `index-single-done`: Emitted when an individual index finishes within `Model#ensureIndexes`. If an error occurred it is passed with the event. The fields, options, and index name are also passed. diff --git a/lib/services/model/applyHooks.js b/lib/services/model/applyHooks.js index f07d49fb056..cff9dd4e9b5 100644 --- a/lib/services/model/applyHooks.js +++ b/lib/services/model/applyHooks.js @@ -123,7 +123,9 @@ function applyHooks(model, schema) { if (error instanceof VersionError) { error.stack = originalError.stack; } - _this.$__handleReject(error); + if (!fn) { + _this.$__handleReject(error); + } reject(error); return; } @@ -140,8 +142,8 @@ function applyHooks(model, schema) { if (this.constructor.$wrapCallback) { fn = this.constructor.$wrapCallback(fn); } - return promise.then( - function() { + promise.then( + function(res) { process.nextTick(function() { fn.apply(null, [null].concat($results)); });