Search in sources :

Example 1 with MongoNodeIsRecoveringException

use of com.mongodb.MongoNodeIsRecoveringException 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;
    }
}
Also used : MongoNodeIsRecoveringException(com.mongodb.MongoNodeIsRecoveringException) MongoException(com.mongodb.MongoException) MongoExecutionTimeoutException(com.mongodb.MongoExecutionTimeoutException) MongoNotPrimaryException(com.mongodb.MongoNotPrimaryException) BsonString(org.bson.BsonString) BsonValue(org.bson.BsonValue)

Aggregations

MongoException (com.mongodb.MongoException)1 MongoExecutionTimeoutException (com.mongodb.MongoExecutionTimeoutException)1 MongoNodeIsRecoveringException (com.mongodb.MongoNodeIsRecoveringException)1 MongoNotPrimaryException (com.mongodb.MongoNotPrimaryException)1 BsonString (org.bson.BsonString)1 BsonValue (org.bson.BsonValue)1