From 8b80b12f54d43c1f5cfb0d5c3255a0197a9f1467 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 21 Nov 2019 21:06:20 +0100 Subject: [PATCH] =?utf8?q?WIP:=20WebClient=20--=20DIE=20L=C3=96SUNG!?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../GraphApiExchangeFilterFunction.java | 8 +++++-- ...ExchangeFilterFunctionIntegrationTest.java | 24 +------------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java index 6642e38..768ec1d 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java @@ -30,12 +30,16 @@ public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction return next .exchange(request) - .doOnError(e -> LOG.debug("ERROR: {}", e)) .flatMap(response -> { return HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series()) - ? Mono.error(GraphApiException.create(response).block()) + ? response + .bodyToMono(String.class) + .flatMap(errorBody -> Mono.error(GraphApiException.create( + response.statusCode(), + response.headers().asHttpHeaders(), + errorBody.getBytes()))) : 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 8614735..0f67543 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java @@ -13,9 +13,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.client.reactive.JettyClientHttpConnector; -import org.springframework.web.reactive.function.client.ClientRequest; -import org.springframework.web.reactive.function.client.ClientResponse; -import org.springframework.web.reactive.function.client.ExchangeFunction; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -43,7 +40,7 @@ public class GraphApiExchangeFilterFunctionIntegrationTest .builder() .clientConnector(new JettyClientHttpConnector()) .baseUrl(server.url("/").toString()) - .filter(this::errorHandlingFilter) + .filter(GraphApiExchangeFilterFunction.INSTANCE) .build(); } @@ -130,23 +127,4 @@ public class GraphApiExchangeFilterFunctionIntegrationTest .expectComplete() .verify(Duration.ofSeconds(3)); } - - public Mono errorHandlingFilter(ClientRequest request, ExchangeFunction next) - { - return - next - .exchange(request) - .flatMap(response -> - { - return - HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series()) - ? response - .bodyToMono(String.class) - .flatMap(errorBody -> Mono.error(GraphApiException.create( - response.statusCode(), - response.headers().asHttpHeaders(), - errorBody.getBytes()))) - : Mono.just(response); - }); - } } -- 2.20.1