From: Kai Moritz Date: Thu, 21 Nov 2019 19:34:38 +0000 (+0100) Subject: WIP: WebClient - DIE LÖSUNG X-Git-Tag: wip-webclient~15 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=2ae7a1699b006ff5dc15fe4a985ba4dc5a208c01;p=facebook-errors WIP: WebClient - DIE LÖSUNG -- Guckst du hier: https://stackoverflow.com/a/48984852/247276 Die spannende Frage ist noch: was macht der anders...? --- 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); } }); }