Search in sources :

Example 1 with IndexNotFoundException

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

the class QueryChunkResponseParser method errorsToThrowable.

static CouchbaseException errorsToThrowable(final byte[] bytes, HttpResponse header, RequestContext ctx) {
    int httpStatus = header != null ? header.status().code() : 0;
    final List<ErrorCodeAndMessage> errors = bytes.length == 0 ? Collections.emptyList() : ErrorCodeAndMessage.fromJsonArray(bytes);
    QueryErrorContext errorContext = new QueryErrorContext(ctx, errors, httpStatus);
    if (errors.size() >= 1) {
        ErrorCodeAndMessage codeAndMessage = errors.get(0);
        int code = codeAndMessage.code();
        String message = codeAndMessage.message();
        int reasonCode = codeAndMessage.reason() != null ? (int) codeAndMessage.reason().getOrDefault("code", 0) : 0;
        if (code == 3000) {
            return new ParsingFailureException(errorContext);
        } else if (PREPARED_ERROR_CODES.contains(code)) {
            return new PreparedStatementFailureException(errorContext, RETRYABLE_PREPARED_ERROR_CODES.contains(code));
        } else if (code == 4300 && message.matches("^.*index .*already exist.*")) {
            return new IndexExistsException(errorContext);
        } else if (code >= 4000 && code < 5000) {
            return new PlanningFailureException(errorContext);
        } else if (code == 12004 || code == 12016 || (code == 5000 && message.matches("^.*index .+ not found.*"))) {
            return new IndexNotFoundException(errorContext);
        } else if (code == 5000 && message.matches("^.*Index .*already exist.*")) {
            return new IndexExistsException(errorContext);
        } else if (code == 5000 && message.contains("limit for number of indexes that can be created per scope has been reached")) {
            return new QuotaLimitedException(errorContext);
        } else if (code >= 5000 && code < 6000) {
            return new InternalServerFailureException(errorContext);
        } else if (code == 12009) {
            if (message.contains("CAS mismatch") || reasonCode == 12033) {
                return new CasMismatchException(errorContext);
            } else if (reasonCode == 17014) {
                return new DocumentNotFoundException(errorContext);
            } else if (reasonCode == 17012) {
                return new DocumentExistsException(errorContext);
            } else {
                return new DmlFailureException(errorContext);
            }
        } else if ((code >= 10000 && code < 11000) || code == 13014) {
            return new AuthenticationFailureException("Could not authenticate query", errorContext, null);
        } else if ((code >= 12000 && code < 13000) || (code >= 14000 && code < 15000)) {
            return new IndexFailureException(errorContext);
        } else if (code == 1065) {
            if (message.contains("query_context")) {
                return FeatureNotAvailableException.scopeLevelQuery(ServiceType.QUERY);
            }
            if (message.contains("preserve_expiry")) {
                return FeatureNotAvailableException.queryPreserveExpiry();
            }
        } else if (code == 1080) {
            // engine will proactively send us a timeout and we need to convert it.
            return new UnambiguousTimeoutException("Query timed out while streaming/receiving rows", new CancellationErrorContext(errorContext));
        } else if (code == 1191 || code == 1192 || code == 1193 || code == 1194) {
            return new RateLimitedException(errorContext);
        } else if (code == 3230) {
            String feature = null;
            if (message.contains("Advisor") || message.contains("Advise")) {
                feature = "Query Index Advisor";
            } else if (message.contains("Window")) {
                feature = "Query Window Functions";
            }
            return FeatureNotAvailableException.communityEdition(feature);
        }
    }
    return new CouchbaseException("Unknown query error", errorContext);
}
Also used : IndexExistsException(com.couchbase.client.core.error.IndexExistsException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) DocumentExistsException(com.couchbase.client.core.error.DocumentExistsException) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) PlanningFailureException(com.couchbase.client.core.error.PlanningFailureException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) QueryErrorContext(com.couchbase.client.core.error.context.QueryErrorContext) QuotaLimitedException(com.couchbase.client.core.error.QuotaLimitedException) ErrorCodeAndMessage(com.couchbase.client.core.error.ErrorCodeAndMessage) ParsingFailureException(com.couchbase.client.core.error.ParsingFailureException) PreparedStatementFailureException(com.couchbase.client.core.error.PreparedStatementFailureException) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) DmlFailureException(com.couchbase.client.core.error.DmlFailureException) IndexFailureException(com.couchbase.client.core.error.IndexFailureException) CancellationErrorContext(com.couchbase.client.core.error.context.CancellationErrorContext) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) InternalServerFailureException(com.couchbase.client.core.error.InternalServerFailureException)

Example 2 with IndexNotFoundException

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

the class SearchChunkResponseParser method errorsToThrowable.

private CouchbaseException errorsToThrowable(final byte[] bytes) {
    int statusCode = responseHeader().status().code();
    String errorDecoded = bytes == null || bytes.length == 0 ? "" : new String(bytes, CharsetUtil.UTF_8);
    SearchErrorContext errorContext = new SearchErrorContext(HttpProtocol.decodeStatus(responseHeader().status()), requestContext(), statusCode, errorDecoded);
    if (statusCode == 400 && errorDecoded.contains("index not found")) {
        return new IndexNotFoundException(errorContext);
    } else if (statusCode == 500) {
        return new InternalServerFailureException(errorContext);
    } else if (statusCode == 401 || statusCode == 403) {
        return new AuthenticationFailureException("Could not authenticate search query", errorContext, null);
    } else if (statusCode == 400 && errorDecoded.contains("num_fts_indexes")) {
        return new QuotaLimitedException(errorContext);
    } else if (statusCode == 429) {
        if (errorDecoded.contains("num_concurrent_requests") || errorDecoded.contains("num_queries_per_min") || errorDecoded.contains("ingress_mib_per_min") || errorDecoded.contains("egress_mib_per_min")) {
            return new RateLimitedException(errorContext);
        }
    }
    return new CouchbaseException("Unknown search error: " + errorDecoded, errorContext);
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) QuotaLimitedException(com.couchbase.client.core.error.QuotaLimitedException) SearchErrorContext(com.couchbase.client.core.error.context.SearchErrorContext) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) InternalServerFailureException(com.couchbase.client.core.error.InternalServerFailureException)

Example 3 with IndexNotFoundException

use of com.couchbase.client.core.error.IndexNotFoundException 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 4 with IndexNotFoundException

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

the class AsyncSearchIndexManager method getIndex.

/**
 * Fetches an index from the server if it exists.
 *
 * @param name the name of the search index.
 * @return a {@link CompletableFuture} the found index once complete.
 */
public CompletableFuture<SearchIndex> getIndex(final String name, GetSearchIndexOptions options) {
    notNullOrEmpty(name, "Search Index Name");
    RequestSpan span = CbTracing.newSpan(core.context(), TracingIdentifiers.SPAN_REQUEST_MS_GET_INDEX, options.build().parentSpan().orElse(null));
    return getAllIndexes(getAllSearchIndexesOptions().parentSpan(span)).thenApply(indexes -> indexes.stream().filter(i -> i.name().equals(name)).findFirst().orElseThrow(() -> new IndexNotFoundException(name))).whenComplete((r, t) -> span.end());
}
Also used : AnalyzeDocumentOptions.analyzeDocumentOptions(com.couchbase.client.java.manager.search.AnalyzeDocumentOptions.analyzeDocumentOptions) HttpHeaderNames(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpHeaderNames) GetSearchIndexOptions.getSearchIndexOptions(com.couchbase.client.java.manager.search.GetSearchIndexOptions.getSearchIndexOptions) Validators.notNull(com.couchbase.client.core.util.Validators.notNull) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) RequestTarget(com.couchbase.client.core.msg.RequestTarget) TypeReference(com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) Map(java.util.Map) CoreHttpPath.path(com.couchbase.client.core.endpoint.http.CoreHttpPath.path) DropSearchIndexOptions.dropSearchIndexOptions(com.couchbase.client.java.manager.search.DropSearchIndexOptions.dropSearchIndexOptions) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) GetAllSearchIndexesOptions.getAllSearchIndexesOptions(com.couchbase.client.java.manager.search.GetAllSearchIndexesOptions.getAllSearchIndexesOptions) CbTracing(com.couchbase.client.core.cnc.CbTracing) AllowQueryingSearchIndexOptions.allowQueryingSearchIndexOptions(com.couchbase.client.java.manager.search.AllowQueryingSearchIndexOptions.allowQueryingSearchIndexOptions) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) Mapper(com.couchbase.client.core.json.Mapper) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) UrlQueryStringBuilder.urlEncode(com.couchbase.client.core.util.UrlQueryStringBuilder.urlEncode) FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) UpsertSearchIndexOptions.upsertSearchIndexOptions(com.couchbase.client.java.manager.search.UpsertSearchIndexOptions.upsertSearchIndexOptions) Collectors(java.util.stream.Collectors) Validators.notNullOrEmpty(com.couchbase.client.core.util.Validators.notNullOrEmpty) PauseIngestSearchIndexOptions.pauseIngestSearchIndexOptions(com.couchbase.client.java.manager.search.PauseIngestSearchIndexOptions.pauseIngestSearchIndexOptions) Objects(java.util.Objects) List(java.util.List) GetIndexedSearchIndexOptions.getIndexedSearchIndexOptions(com.couchbase.client.java.manager.search.GetIndexedSearchIndexOptions.getIndexedSearchIndexOptions) UnfreezePlanSearchIndexOptions.unfreezePlanSearchIndexOptions(com.couchbase.client.java.manager.search.UnfreezePlanSearchIndexOptions.unfreezePlanSearchIndexOptions) ResumeIngestSearchIndexOptions.resumeIngestSearchIndexOptions(com.couchbase.client.java.manager.search.ResumeIngestSearchIndexOptions.resumeIngestSearchIndexOptions) JsonObject(com.couchbase.client.java.json.JsonObject) FreezePlanSearchIndexOptions.freezePlanSearchIndexOptions(com.couchbase.client.java.manager.search.FreezePlanSearchIndexOptions.freezePlanSearchIndexOptions) Core(com.couchbase.client.core.Core) DisallowQueryingSearchIndexOptions.disallowQueryingSearchIndexOptions(com.couchbase.client.java.manager.search.DisallowQueryingSearchIndexOptions.disallowQueryingSearchIndexOptions) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

CouchbaseException (com.couchbase.client.core.error.CouchbaseException)4 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)4 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)3 InternalServerFailureException (com.couchbase.client.core.error.InternalServerFailureException)3 ErrorCodeAndMessage (com.couchbase.client.core.error.ErrorCodeAndMessage)2 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)2 ParsingFailureException (com.couchbase.client.core.error.ParsingFailureException)2 QuotaLimitedException (com.couchbase.client.core.error.QuotaLimitedException)2 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)2 Core (com.couchbase.client.core.Core)1 CbTracing (com.couchbase.client.core.cnc.CbTracing)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 TypeReference (com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)1 HttpHeaderNames (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpHeaderNames)1 CoreHttpClient (com.couchbase.client.core.endpoint.http.CoreHttpClient)1 CoreHttpPath.path (com.couchbase.client.core.endpoint.http.CoreHttpPath.path)1 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)1 CompilationFailureException (com.couchbase.client.core.error.CompilationFailureException)1