Java Code Examples for com.couchbase.client.core.message.ResponseStatus#FAILURE

The following examples show how to use com.couchbase.client.core.message.ResponseStatus#FAILURE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseStatusConverter.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the http protocol status in a typesafe enum that can be acted upon later.
 *
 * @param code the status to convert.
 * @return the converted response status.
 */
public static ResponseStatus fromHttp(final int code) {
    ResponseStatus status;
    switch (code) {
        case HTTP_OK:
        case HTTP_CREATED:
        case HTTP_ACCEPTED:
            status = ResponseStatus.SUCCESS;
            break;
        case HTTP_NOT_FOUND:
            status = ResponseStatus.NOT_EXISTS;
            break;
        case HTTP_BAD_REQUEST:
            status = ResponseStatus.INVALID_ARGUMENTS;
            break;
        case HTTP_INTERNAL_ERROR:
            status = ResponseStatus.INTERNAL_ERROR;
            break;
        case HTTP_UNAUTHORIZED:
            status = ResponseStatus.ACCESS_ERROR;
            break;
        case HTTP_TOO_MANY_REQUESTS:
            status = ResponseStatus.FAILURE;
            break;
        default:
            LOGGER.warn("Unknown ResponseStatus with Protocol HTTP: {}", code);
            status = ResponseStatus.FAILURE;
    }
    return status;
}
 
Example 2
Source File: ResponseStatusConverter.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
/**
 * Convert the binary protocol status in a typesafe enum that can be acted upon later.
 *
 * @param code the status to convert.
 * @return the converted response status.
 */
public static ResponseStatus fromBinary(final short code) {
    KeyValueStatus status = KeyValueStatus.valueOf(code);
    switch (status) {
        case SUCCESS:
            return ResponseStatus.SUCCESS;
        case ERR_EXISTS:
            return ResponseStatus.EXISTS;
        case ERR_NOT_FOUND:
            return ResponseStatus.NOT_EXISTS;
        case ERR_NOT_MY_VBUCKET:
            return ResponseStatus.RETRY;
        case ERR_NOT_STORED:
            return ResponseStatus.NOT_STORED;
        case ERR_TOO_BIG:
            return ResponseStatus.TOO_BIG;
        case ERR_TEMP_FAIL:
            return ResponseStatus.TEMPORARY_FAILURE;
        case ERR_BUSY:
            return ResponseStatus.SERVER_BUSY;
        case ERR_NO_MEM:
            return ResponseStatus.OUT_OF_MEMORY;
        case ERR_UNKNOWN_COMMAND:
            return ResponseStatus.COMMAND_UNAVAILABLE;
        case ERR_NOT_SUPPORTED:
            return ResponseStatus.COMMAND_UNAVAILABLE;
        case ERR_ACCESS:
            return ResponseStatus.ACCESS_ERROR;
        case ERR_INTERNAL:
            return ResponseStatus.INTERNAL_ERROR;
        case ERR_INVALID:
            return ResponseStatus.INVALID_ARGUMENTS;
        case ERR_DELTA_BADVAL:
            return ResponseStatus.INVALID_ARGUMENTS;
        case ERR_RANGE:
            return ResponseStatus.RANGE_ERROR;
        case ERR_ROLLBACK:
            return ResponseStatus.ROLLBACK;
        //== the following codes are for subdocument API ==
        case ERR_SUBDOC_PATH_NOT_FOUND:
            return ResponseStatus.SUBDOC_PATH_NOT_FOUND;
        case ERR_SUBDOC_PATH_MISMATCH:
            return ResponseStatus.SUBDOC_PATH_MISMATCH;
        case ERR_SUBDOC_PATH_INVALID:
            return ResponseStatus.SUBDOC_PATH_INVALID;
        case ERR_SUBDOC_PATH_TOO_BIG:
            return ResponseStatus.SUBDOC_PATH_TOO_BIG;
        case ERR_SUBDOC_DOC_TOO_DEEP:
            return ResponseStatus.SUBDOC_DOC_TOO_DEEP;
        case ERR_SUBDOC_VALUE_CANTINSERT:
            return ResponseStatus.SUBDOC_VALUE_CANTINSERT;
        case ERR_SUBDOC_DOC_NOT_JSON:
            return ResponseStatus.SUBDOC_DOC_NOT_JSON;
        case ERR_SUBDOC_NUM_RANGE:
            return ResponseStatus.SUBDOC_NUM_RANGE;
        case ERR_SUBDOC_DELTA_RANGE:
            return ResponseStatus.SUBDOC_DELTA_RANGE;
        case ERR_SUBDOC_PATH_EXISTS:
            return ResponseStatus.SUBDOC_PATH_EXISTS;
        case ERR_SUBDOC_VALUE_TOO_DEEP:
            return ResponseStatus.SUBDOC_VALUE_TOO_DEEP;
        case ERR_SUBDOC_INVALID_COMBO:
            return ResponseStatus.SUBDOC_INVALID_COMBO;
        case ERR_SUBDOC_MULTI_PATH_FAILURE:
            return ResponseStatus.SUBDOC_MULTI_PATH_FAILURE;
        case ERR_SUBDOC_XATTR_INVALID_FLAG_COMBO:
            return ResponseStatus.INTERNAL_ERROR;
        case ERR_SUBDOC_XATTR_UNKNOWN_MACRO:
            return ResponseStatus.SUBDOC_XATTR_UNKNOWN_MACRO;
        case ERR_SUBDOC_XATTR_INVALID_KEY_COMBO:
            return ResponseStatus.SUBDOC_XATTR_INVALID_KEY_COMBO;
        //== end of subdocument API codes ==
    }
    return ResponseStatus.FAILURE;
}
 
Example 3
Source File: MultiMutationResponse.java    From couchbase-jvm-core with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a {@link MultiMutationResponse} that failed at subdocument level. The status, expected to be
 * {@link ResponseStatus#SUBDOC_MULTI_PATH_FAILURE}, denotes that at least one {@link MutationCommand} failed.
 *
 * @param status the status of the request (SUBDOC_MULTI_PATH_FAILURE).
 * @param serverStatusCode the status code of the whole request.
 * @param bucket the bucket on which the request happened.
 * @param firstErrorIndex the zero-based index of the first {@link MutationCommand} that failed (in case failure is
 *                        due to one or more commands).
 * @param firstErrorStatusCode the status code for the first {@link MutationCommand} that failed (in case failure is
 *                        due to one or more commands).
 * @param request the original {@link BinarySubdocMultiMutationRequest}.
 * @param cas the CAS value of the document after mutations.
 * @param mutationToken the {@link MutationToken} of the document after mutations, if available. Null otherwise.
 */
public MultiMutationResponse(ResponseStatus status, short serverStatusCode, String bucket, int firstErrorIndex, short firstErrorStatusCode,
                            BinarySubdocMultiMutationRequest request, long cas, MutationToken mutationToken) { //do cas and muto make sense here?
    super(status, serverStatusCode, bucket, Unpooled.EMPTY_BUFFER, request);
    this.cas = cas;
    this.mutationToken = mutationToken;
    this.firstErrorIndex = firstErrorIndex;
    if (firstErrorIndex == -1) {
        this.firstErrorStatus = ResponseStatus.FAILURE;
    } else {
        this.firstErrorStatus = ResponseStatusConverter.fromBinary(firstErrorStatusCode);
    }
    this.responses = Collections.emptyList();
}
 
Example 4
Source File: MultiMutationResponse.java    From couchbase-jvm-core with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a unsuccessful {@link MultiMutationResponse} that failed at document level.
 *
 * First error index is set to -1 and first error status is set to {@link ResponseStatus#FAILURE}.
 *
 * @param status the failed status of the request.
 * @param serverStatusCode the status code of the whole request.
 * @param bucket the bucket on which the request happened.
 * @param request the original {@link BinarySubdocMultiMutationRequest}.
 * @param cas the CAS value of the document after mutations.
 * @param mutationToken the {@link MutationToken} of the document after mutations, if available. Null otherwise.
 */
public MultiMutationResponse(ResponseStatus status, short serverStatusCode, String bucket,
                             BinarySubdocMultiMutationRequest request, long cas, MutationToken mutationToken) { //do cas and muto make sense here?
    super(status, serverStatusCode, bucket, Unpooled.EMPTY_BUFFER, request);
    this.cas = cas;
    this.mutationToken = mutationToken;
    this.firstErrorIndex = -1;
    this.firstErrorStatus = ResponseStatus.FAILURE;
    this.responses = Collections.emptyList();
}