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

Commit 24c5d06

Browse files
authoredJun 21, 2018
fix(error): attach command response to MongoWriteConcernError (#322)
Fixes NODE-1521
1 parent 245546c commit 24c5d06

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
 

‎lib/connection/pool.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,11 @@ function messageHandler(self) {
581581
}
582582

583583
if (responseDoc.writeConcernError) {
584-
return handleOperationCallback(
585-
self,
586-
workItem.cb,
587-
new MongoWriteConcernError(responseDoc.writeConcernError)
588-
);
584+
const err =
585+
responseDoc.ok === 1
586+
? new MongoWriteConcernError(responseDoc.writeConcernError, responseDoc)
587+
: new MongoWriteConcernError(responseDoc.writeConcernError);
588+
return handleOperationCallback(self, workItem.cb, err);
589589
}
590590
}
591591

‎lib/error.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,19 @@ function isRetryableError(error) {
130130
*
131131
* @class
132132
* @param {Error|string|object} message The error message
133+
* @param {object} result The result document (provided if ok: 1)
133134
* @property {string} message The error message
135+
* @property {object} [result] The result document (provided if ok: 1)
134136
* @return {MongoWriteConcernError} A MongoWriteConcernError instance
135137
* @extends {MongoError}
136138
*/
137-
const MongoWriteConcernError = function(message) {
139+
const MongoWriteConcernError = function(message, result) {
138140
MongoError.call(this, message);
139141
this.name = 'MongoWriteConcernError';
142+
143+
if (result != null) {
144+
this.result = result;
145+
}
140146
};
141147
util.inherits(MongoWriteConcernError, MongoError);
142148

0 commit comments

Comments
 (0)
This repository has been archived.