diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-06-28 15:39:14 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-06-28 15:39:14 +0200 |
commit | c640a7c53cd5cc7ecc42e024bc668df4ef0cbba6 (patch) | |
tree | 758fd7deac9c924bd0abd8f8f8aeb4f0f0edc607 /vespa-feed-client | |
parent | 34a24e7d7deccff5224619a927a88ba90e3c07f9 (diff) |
Ensure we propagate FeedException
Diffstat (limited to 'vespa-feed-client')
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java | 17 |
1 files changed, 15 insertions, 2 deletions
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<Result> 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 }; |