Skip to content

Commit

Permalink
Add top-level error labels to write concern error (mongodb#766)
Browse files Browse the repository at this point in the history
This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
  • Loading branch information
jyemin committed Jul 27, 2021
1 parent c3c0a2c commit 81cc1a7
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -243,7 +243,14 @@ public static MongoException createSpecialException(final BsonDocument response,
} else if (errorMessage.contains("not master") || NOT_MASTER_CODES.contains(errorCode)) {
return new MongoNotPrimaryException(response, serverAddress);
} else if (response.containsKey("writeConcernError")) {
return createSpecialException(response.getDocument("writeConcernError"), serverAddress, "errmsg");
MongoException writeConcernException = createSpecialException(response.getDocument("writeConcernError"), serverAddress,
"errmsg");
if (writeConcernException != null && response.isArray("errorLabels")) {
for (BsonValue errorLabel : response.getArray("errorLabels")) {
writeConcernException.addLabel(errorLabel.asString().getValue());
}
}
return writeConcernException;
} else {
return null;
}
Expand Down

0 comments on commit 81cc1a7

Please sign in to comment.