Search in sources :

Example 1 with AnalyticsErrorContext

use of com.couchbase.client.core.error.context.AnalyticsErrorContext in project couchbase-jvm-clients by couchbase.

the class AnalyticsChunkResponseParser method errorsToThrowable.

@Stability.Internal
static CouchbaseException errorsToThrowable(final byte[] bytes, RequestContext ctx, HttpResponseStatus httpStatus) {
    int httpCode = httpStatus != null ? httpStatus.code() : 0;
    final List<ErrorCodeAndMessage> errors = bytes.length == 0 ? Collections.emptyList() : ErrorCodeAndMessage.from(bytes);
    AnalyticsErrorContext errorContext = new AnalyticsErrorContext(ctx, errors, httpCode);
    if (errors.size() >= 1) {
        ErrorCodeAndMessage error = errors.get(0);
        // Analytics error code reference:
        // https://docs.couchbase.com/server/current/analytics/error-codes.html
        int code = error.code();
        if (code >= 25000 && code < 26000) {
            return new InternalServerFailureException(errorContext);
        } else if (code >= 20000 && code < 21000) {
            return new AuthenticationFailureException("Could not authenticate analytics query", errorContext, null);
        } else if (code == 23000 || code == 23003) {
            return new TemporaryFailureException(errorContext);
        } else if (code == 23007) {
            return new JobQueueFullException(errorContext);
        } else if (code == 24000) {
            return new ParsingFailureException(errorContext);
        } else if (code == 24006) {
            return new LinkNotFoundException(errorContext);
        } else if (code == 24055) {
            return new LinkExistsException(errorContext);
        } else if (code == 24040) {
            return new DatasetExistsException(errorContext);
        } else if (code == 24044 || code == 24045 || code == 24025) {
            return new DatasetNotFoundException(errorContext);
        } else if (code == 24034) {
            return new DataverseNotFoundException(errorContext);
        } else if (code == 24039) {
            return new DataverseExistsException(errorContext);
        } else if (code == 24047) {
            return new IndexNotFoundException(errorContext);
        } else if (code == 24048) {
            return new IndexExistsException(errorContext);
        } else if (code > 24000 && code < 25000) {
            return new CompilationFailureException(errorContext);
        } else {
            return new CouchbaseException("Unknown analytics error: " + error, errorContext);
        }
    }
    return new CouchbaseException("Unknown analytics error", errorContext);
}
Also used : AnalyticsErrorContext(com.couchbase.client.core.error.context.AnalyticsErrorContext) DataverseNotFoundException(com.couchbase.client.core.error.DataverseNotFoundException) DataverseExistsException(com.couchbase.client.core.error.DataverseExistsException) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) TemporaryFailureException(com.couchbase.client.core.error.TemporaryFailureException) LinkNotFoundException(com.couchbase.client.core.error.LinkNotFoundException) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) CompilationFailureException(com.couchbase.client.core.error.CompilationFailureException) DatasetExistsException(com.couchbase.client.core.error.DatasetExistsException) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) JobQueueFullException(com.couchbase.client.core.error.JobQueueFullException) ErrorCodeAndMessage(com.couchbase.client.core.error.ErrorCodeAndMessage) ParsingFailureException(com.couchbase.client.core.error.ParsingFailureException) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) DatasetNotFoundException(com.couchbase.client.core.error.DatasetNotFoundException) LinkExistsException(com.couchbase.client.core.error.LinkExistsException) InternalServerFailureException(com.couchbase.client.core.error.InternalServerFailureException)

Example 2 with AnalyticsErrorContext

use of com.couchbase.client.core.error.context.AnalyticsErrorContext in project couchbase-jvm-clients by couchbase.

the class CoreAnalyticsLinkManager method translateCompilationFailureToInvalidArgument.

private static RuntimeException translateCompilationFailureToInvalidArgument(Throwable t) {
    if (!(t.getCause() instanceof CompilationFailureException)) {
        CbThrowables.throwIfUnchecked(t);
        throw new CouchbaseException(t.getMessage(), t);
    }
    CompilationFailureException e = (CompilationFailureException) t.getCause();
    String message = ((AnalyticsErrorContext) e.context()).errors().get(0).message();
    throw new InvalidArgumentException(message, e.getCause(), e.context());
}
Also used : AnalyticsErrorContext(com.couchbase.client.core.error.context.AnalyticsErrorContext) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) Builder.newQueryString(com.couchbase.client.core.endpoint.http.CoreHttpRequest.Builder.newQueryString) CompilationFailureException(com.couchbase.client.core.error.CompilationFailureException)

Aggregations

CompilationFailureException (com.couchbase.client.core.error.CompilationFailureException)2 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)2 AnalyticsErrorContext (com.couchbase.client.core.error.context.AnalyticsErrorContext)2 Builder.newQueryString (com.couchbase.client.core.endpoint.http.CoreHttpRequest.Builder.newQueryString)1 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)1 DatasetExistsException (com.couchbase.client.core.error.DatasetExistsException)1 DatasetNotFoundException (com.couchbase.client.core.error.DatasetNotFoundException)1 DataverseExistsException (com.couchbase.client.core.error.DataverseExistsException)1 DataverseNotFoundException (com.couchbase.client.core.error.DataverseNotFoundException)1 ErrorCodeAndMessage (com.couchbase.client.core.error.ErrorCodeAndMessage)1 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)1 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)1 InternalServerFailureException (com.couchbase.client.core.error.InternalServerFailureException)1 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)1 JobQueueFullException (com.couchbase.client.core.error.JobQueueFullException)1 LinkExistsException (com.couchbase.client.core.error.LinkExistsException)1 LinkNotFoundException (com.couchbase.client.core.error.LinkNotFoundException)1 ParsingFailureException (com.couchbase.client.core.error.ParsingFailureException)1 TemporaryFailureException (com.couchbase.client.core.error.TemporaryFailureException)1