Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(error): attach command response to MongoWriteConcernError (#322)
Browse files Browse the repository at this point in the history
Fixes NODE-1521
  • Loading branch information
kvwalker committed Jun 21, 2018
1 parent 245546c commit 24c5d06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/connection/pool.js
Expand Up @@ -581,11 +581,11 @@ function messageHandler(self) {
}

if (responseDoc.writeConcernError) {
return handleOperationCallback(
self,
workItem.cb,
new MongoWriteConcernError(responseDoc.writeConcernError)
);
const err =
responseDoc.ok === 1
? new MongoWriteConcernError(responseDoc.writeConcernError, responseDoc)
: new MongoWriteConcernError(responseDoc.writeConcernError);
return handleOperationCallback(self, workItem.cb, err);
}
}

Expand Down
8 changes: 7 additions & 1 deletion lib/error.js
Expand Up @@ -130,13 +130,19 @@ function isRetryableError(error) {
*
* @class
* @param {Error|string|object} message The error message
* @param {object} result The result document (provided if ok: 1)
* @property {string} message The error message
* @property {object} [result] The result document (provided if ok: 1)
* @return {MongoWriteConcernError} A MongoWriteConcernError instance
* @extends {MongoError}
*/
const MongoWriteConcernError = function(message) {
const MongoWriteConcernError = function(message, result) {
MongoError.call(this, message);
this.name = 'MongoWriteConcernError';

if (result != null) {
this.result = result;
}
};
util.inherits(MongoWriteConcernError, MongoError);

Expand Down

0 comments on commit 24c5d06

Please sign in to comment.