From 2ae7a1699b006ff5dc15fe4a985ba4dc5a208c01 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 21 Nov 2019 20:34:38 +0100 Subject: [PATCH] =?utf8?q?WIP:=20WebClient=20-=20DIE=20L=C3=96SUNG=20--=20?= =?utf8?q?Guckst=20du=20hier:=20https://stackoverflow.com/a/48984852/24727?= =?utf8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Die spannende Frage ist noch: was macht der anders...? --- ...piExchangeFilterFunctionIntegrationTest.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java index 306f044..8d21cc5 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java @@ -11,6 +11,7 @@ import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.client.reactive.JettyClientHttpConnector; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; @@ -41,6 +42,7 @@ public class GraphApiExchangeFilterFunctionIntegrationTest .builder() .clientConnector(new JettyClientHttpConnector()) .baseUrl(server.url("/").toString()) + .filter(errorHandlingFilter()) .build(); } @@ -74,7 +76,6 @@ public class GraphApiExchangeFilterFunctionIntegrationTest .get() .uri("/egal") .retrieve() - .onStatus(status -> status.is4xxClientError(), response -> GraphApiException.create(response)) .bodyToMono(String.class); StepVerifier @@ -105,7 +106,6 @@ public class GraphApiExchangeFilterFunctionIntegrationTest result = webClient.get() .uri("/greeting?name=Spring") .retrieve() - .onStatus(status -> status.is4xxClientError(), response -> GraphApiException.create(response)) .bodyToMono(String.class); StepVerifier.create(result) @@ -122,7 +122,6 @@ public class GraphApiExchangeFilterFunctionIntegrationTest result = webClient.get() .uri("/greeting?name=Spring") .retrieve() - .onStatus(status -> status.is4xxClientError(), response -> GraphApiException.create(response)) .bodyToMono(String.class); StepVerifier.create(result) @@ -133,20 +132,20 @@ public class GraphApiExchangeFilterFunctionIntegrationTest public static ExchangeFilterFunction errorHandlingFilter() { - return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> + return ExchangeFilterFunction.ofResponseProcessor(response -> { - if (clientResponse.statusCode() != null && (clientResponse.statusCode() - .is5xxServerError() || clientResponse.statusCode().is4xxClientError())) + if (response.statusCode() != null && (response.statusCode() + .is5xxServerError() || response.statusCode().is4xxClientError())) { - return clientResponse.bodyToMono(String.class) + return response.bodyToMono(String.class) .flatMap(errorBody -> { - return Mono.error(new Exception(errorBody)); + return Mono.error(GraphApiException.create(response.statusCode(), response.headers().asHttpHeaders(), errorBody.getBytes())); }); } else { - return Mono.just(clientResponse); + return Mono.just(response); } }); } -- 2.20.1