use of com.mongodb.MongoNotPrimaryException in project mongo-java-driver by mongodb.
the class ProtocolHelper method createSpecialException.
public static MongoException createSpecialException(final BsonDocument response, final ServerAddress serverAddress, final String errorMessageFieldName) {
if (response == null) {
return null;
}
int errorCode = getErrorCode(response);
String errorMessage = getErrorMessage(response, errorMessageFieldName);
if (ErrorCategory.fromErrorCode(errorCode) == ErrorCategory.EXECUTION_TIMEOUT) {
return new MongoExecutionTimeoutException(errorCode, errorMessage, response);
} else if (isNodeIsRecoveringError(errorCode, errorMessage)) {
return new MongoNodeIsRecoveringException(response, serverAddress);
} else if (isNotPrimaryError(errorCode, errorMessage)) {
return new MongoNotPrimaryException(response, serverAddress);
} else if (response.containsKey("writeConcernError")) {
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;
}
}
Aggregations