Search in sources :

Example 1 with ErrorCode

use of com.eightkdata.mongowp.ErrorCode in project torodb by torodb.

the class TopologyHeartbeatHandler method handleHeartbeatError.

@Nonnull
private RemoteCommandResponse<ReplSetHeartbeatReply> handleHeartbeatError(Throwable t, Instant start) {
    Duration d = Duration.between(clock.instant(), start);
    ErrorCode errorCode;
    if (t instanceof MongoException) {
        return new FromExceptionRemoteCommandRequest((MongoException) t, d);
    } else if (t instanceof UnreachableMongoServerException) {
        errorCode = ErrorCode.HOST_UNREACHABLE;
    } else {
        if (!(t instanceof MongoRuntimeException) && !(t instanceof UnreachableMongoServerException)) {
            LOGGER.warn("Unexpected exception {} catched by the topology " + "heartbeat handler", t.getClass().getSimpleName());
        }
        errorCode = ErrorCode.UNKNOWN_ERROR;
    }
    return new ErroneousRemoteCommandResponse<>(errorCode, t.getLocalizedMessage(), d);
}
Also used : MongoException(com.eightkdata.mongowp.exceptions.MongoException) UnreachableMongoServerException(com.eightkdata.mongowp.client.core.UnreachableMongoServerException) Duration(java.time.Duration) MongoRuntimeException(com.eightkdata.mongowp.server.api.MongoRuntimeException) ErrorCode(com.eightkdata.mongowp.ErrorCode) ErroneousRemoteCommandResponse(com.eightkdata.mongowp.client.core.MongoConnection.ErroneousRemoteCommandResponse) FromExceptionRemoteCommandRequest(com.eightkdata.mongowp.client.core.MongoConnection.FromExceptionRemoteCommandRequest) Nonnull(javax.annotation.Nonnull)

Example 2 with ErrorCode

use of com.eightkdata.mongowp.ErrorCode in project torodb by torodb.

the class ReplSetHeartbeatReplyMarshaller method checkCommandError.

private static void checkCommandError(BsonDocument bson, String setName) throws MongoException {
    if (setName == null && !BsonReaderTool.isPseudoTrue(bson, OK_FIELD)) {
        String errMsg = BsonReaderTool.getString(bson, ERR_MSG_FIELD, "");
        assert errMsg != null;
        Entry<?> errorCodeEntry = BsonReaderTool.getEntry(bson, ERROR_CODE_FIELD, null);
        if (errorCodeEntry != null) {
            if (!errorCodeEntry.getValue().isNumber()) {
                throw new BadValueException(ERROR_CODE_FIELD + " is " + "not a number");
            }
            ErrorCode errorCode = ErrorCode.fromErrorCode(errorCodeEntry.getValue().asNumber().intValue());
            throw new MongoException(errMsg, errorCode);
        }
        throw new UnknownErrorException(errMsg);
    }
}
Also used : BadValueException(com.eightkdata.mongowp.exceptions.BadValueException) MongoException(com.eightkdata.mongowp.exceptions.MongoException) UnknownErrorException(com.eightkdata.mongowp.exceptions.UnknownErrorException) ErrorCode(com.eightkdata.mongowp.ErrorCode)

Aggregations

ErrorCode (com.eightkdata.mongowp.ErrorCode)2 MongoException (com.eightkdata.mongowp.exceptions.MongoException)2 ErroneousRemoteCommandResponse (com.eightkdata.mongowp.client.core.MongoConnection.ErroneousRemoteCommandResponse)1 FromExceptionRemoteCommandRequest (com.eightkdata.mongowp.client.core.MongoConnection.FromExceptionRemoteCommandRequest)1 UnreachableMongoServerException (com.eightkdata.mongowp.client.core.UnreachableMongoServerException)1 BadValueException (com.eightkdata.mongowp.exceptions.BadValueException)1 UnknownErrorException (com.eightkdata.mongowp.exceptions.UnknownErrorException)1 MongoRuntimeException (com.eightkdata.mongowp.server.api.MongoRuntimeException)1 Duration (java.time.Duration)1 Nonnull (javax.annotation.Nonnull)1