-
Notifications
You must be signed in to change notification settings - Fork 106
fix(error): attach command response to MongoWriteConcernError #322
Conversation
Fixes NODE-1521
lib/error.js
Outdated
const MongoWriteConcernError = function(message) { | ||
MongoError.call(this, message); | ||
const MongoWriteConcernError = function(message, result) { | ||
MongoError.call(this, message, result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to pass result
to MongoError
? It doesn't appear to do anything with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, thanks for catching that!
lib/connection/pool.js
Outdated
@@ -581,6 +581,13 @@ function messageHandler(self) { | |||
} | |||
|
|||
if (responseDoc.writeConcernError) { | |||
if (responseDoc.ok === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about doing a ternary to create the error, and then using a single callback?
if (responseDoc.writeConcernError) {
const err = responseDoc.ok === 1 ?
new MongoWriteConcernError(responseDoc.writeConcernError, responseDoc) :
new MongoWriteConcernError(responseDoc.writeConcernError);
return handleOperationCallback(self, workItem.cb, err);
}
lib/error.js
Outdated
@@ -131,12 +131,17 @@ function isRetryableError(error) { | |||
* @class | |||
* @param {Error|string|object} message The error message | |||
* @property {string} message The error message | |||
* @property {object} result The result document (provided if ok: 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap the name of the argument with brackets to indicate it is optional, and add it to the @param
documentation.
Fixes NODE-1521