From 856a32e22b7a0e383c0ea2cf8ad3885ac9f08e36 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 21 Nov 2019 15:28:19 +0100 Subject: [PATCH] WIP: WebClient --- .../java/de/juplo/facebook/errors/GraphApiException.java | 8 +++++--- .../facebook/errors/GraphApiExchangeFilterFunction.java | 2 +- .../GraphApiExchangeFilterFunctionIntegrationTest.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiException.java b/src/main/java/de/juplo/facebook/errors/GraphApiException.java index 3f9c544..3ebc64f 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiException.java @@ -48,12 +48,14 @@ public class GraphApiException extends RuntimeException - public static GraphApiException create(ClientResponse response) + public static Mono create(ClientResponse response) { HttpStatus status = response.statusCode(); HttpHeaders headers = response.headers().asHttpHeaders(); - Mono body = response.bodyToMono(String.class); - return create(status , headers, body.block().getBytes()); + return + response + .bodyToMono(InputStream.class) + .map(is -> create(status , headers, is)); } public static GraphApiException create( diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java index 53bdd0b..6642e38 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java @@ -35,7 +35,7 @@ public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction { return HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series()) - ? Mono.error(GraphApiException.create(response)) + ? Mono.error(GraphApiException.create(response).block()) : Mono.just(response); }); } diff --git a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java index c468590..b90e057 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java @@ -103,7 +103,7 @@ public class GraphApiExchangeFilterFunctionIntegrationTest .filter((request, next) -> next.exchange(request).flatMap(response -> { List headerValues = response.headers().header("Foo"); - return headerValues.isEmpty() ? Mono.error(GraphApiException.create(response)) : + return headerValues.isEmpty() ? Mono.error(GraphApiException.create(response).block()) : Mono.just(response); })) .build(); -- 2.20.1