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);
}
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());
}
Aggregations