Search in sources :

Example 1 with KeyValueErrorContext

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

the class MutateInAccessor method mutateIn.

public static CompletableFuture<MutateInResult> mutateIn(final Core core, final SubdocMutateRequest request, final String key, final PersistTo persistTo, final ReplicateTo replicateTo, final Boolean insertDocument, final JsonSerializer serializer) {
    core.send(request);
    final CompletableFuture<MutateInResult> mutateInResult = request.response().thenApply(response -> {
        if (response.status().success()) {
            return new MutateInResult(response.values(), response.cas(), response.mutationToken(), serializer);
        }
        final KeyValueErrorContext ctx = KeyValueErrorContext.completedRequest(request, response.status());
        if (insertDocument && response.status() == ResponseStatus.EXISTS) {
            throw new DocumentExistsException(ctx);
        } else if (response.status() == ResponseStatus.SUBDOC_FAILURE && response.error().isPresent()) {
            throw response.error().get();
        }
        throw keyValueStatusToException(request, response);
    });
    return wrapWithDurability(mutateInResult, key, persistTo, replicateTo, core, request, false);
}
Also used : KeyValueErrorContext(com.couchbase.client.core.error.context.KeyValueErrorContext) DocumentExistsException(com.couchbase.client.core.error.DocumentExistsException)

Aggregations

DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1 KeyValueErrorContext (com.couchbase.client.core.error.context.KeyValueErrorContext)1