From c640a7c53cd5cc7ecc42e024bc668df4ef0cbba6 Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Mon, 28 Jun 2021 15:39:14 +0200 Subject: Ensure we propagate FeedException --- .../main/java/ai/vespa/feed/client/HttpFeedClient.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'vespa-feed-client/src/main/java') diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java index 143f51a9bf7..6e0d9aa5ec2 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.Map; import java.util.StringJoiner; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; @@ -84,8 +85,20 @@ class HttpFeedClient implements FeedClient { requestHeaders, operationJson == null ? null : operationJson.getBytes(UTF_8)); // TODO: make it bytes all the way? - return requestStrategy.enqueue(documentId, request) - .thenApply(response -> toResult(request, response, documentId)); + CompletableFuture promise = new CompletableFuture<>(); + requestStrategy.enqueue(documentId, request) + .thenApply(response -> toResult(request, response, documentId)) + .whenComplete((result, thrown) -> { + if (thrown != null) { + while (thrown instanceof CompletionException) + thrown = thrown.getCause(); + + promise.completeExceptionally(thrown); + } + else + promise.complete(result); + }); + return promise; } private enum Outcome { success, conditionNotMet, vespaFailure, transportFailure }; -- cgit v1.2.3