Skip to content

Commit

Permalink
fix(document): don't emit model error if callback specified for consi…
Browse files Browse the repository at this point in the history
…stency with docs

Fix #5216
  • Loading branch information
vkarpov15 committed May 12, 2017
1 parent 7182998 commit 0eda07a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions lib/services/model/applyHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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));
});
Expand Down

0 comments on commit 0eda07a

Please sign in to comment.