WIP: WebClient wip-webclient
authorKai Moritz <kai@jupl.de>
Fri, 22 Nov 2019 06:25:03 +0000 (07:25 +0100)
committerKai Moritz <kai@jupl.de>
Fri, 22 Nov 2019 06:25:03 +0000 (07:25 +0100)
src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java
src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java

index 6ab18b6..34ca5a7 100644 (file)
@@ -6,6 +6,7 @@ import org.springframework.web.reactive.function.client.ClientRequest;
 import org.springframework.web.reactive.function.client.ClientResponse;
 import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
 import org.springframework.web.reactive.function.client.ExchangeFunction;
+import org.springframework.web.reactive.function.client.WebClientResponseException;
 import reactor.core.publisher.Mono;
 
 
@@ -31,6 +32,16 @@ public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction
                               response.statusCode(),
                               response.headers().asHttpHeaders(),
                               errorBody.getBytes()))
+                          .map(e ->
+                              e.getClass().equals(ErrorResponseParsingErrorException.class)
+                                  ? WebClientResponseException
+                                      .create(
+                                          e.getStatus().value(),
+                                          e.getStatus().getReasonPhrase(),
+                                          e.getHeaders(),
+                                          null,
+                                          null)
+                                  : e)
                           .flatMap(e -> Mono.error(e))
                       : Mono.just(response);
             });
index 9faae0f..53b2e6a 100644 (file)
@@ -59,24 +59,24 @@ public class GraphApiExchangeFilterFunctionIntegrationTest
     Mono<String> result;
 
 
-    server
-        .enqueue(new MockResponse()
-            .setResponseCode(HttpStatus.CONTINUE.value())
-            .setHeader("Content-Type", "application/json")
-            .setBody("Hallo Welt!"));
-    
-    result =
-        webClient
-            .get()
-            .uri("/egal")
-            .retrieve()
-            .bodyToMono(String.class);
-
-    StepVerifier
-        .create(result)
-        .expectNext("Hallo Welt!")
-        .expectComplete()
-        .verify();
+    //server
+    //    .enqueue(new MockResponse()
+    //        .setResponseCode(HttpStatus.CONTINUE.value())
+    //        .setHeader("Content-Type", "application/json")
+    //        .setBody("Hallo Welt!"));
+    //
+    //result =
+    //    webClient
+    //        .get()
+    //        .uri("/egal")
+    //        .retrieve()
+    //        .bodyToMono(String.class);
+    //
+    //StepVerifier
+    //    .create(result)
+    //    .expectNext("Hallo Welt!")
+    //    .expectComplete()
+    //    .verify();
 
 
     server
@@ -102,6 +102,12 @@ public class GraphApiExchangeFilterFunctionIntegrationTest
     server
         .enqueue(new MockResponse()
             .setResponseCode(HttpStatus.TEMPORARY_REDIRECT.value())
+            .setHeader("Location", server.url("/woanders"))
+            .setHeader("Content-Type", "text/plain")
+            .setBody("Jetzt doch woanders..."));
+    server
+        .enqueue(new MockResponse()
+            .setResponseCode(HttpStatus.OK.value())
             .setHeader("Content-Type", "text/plain")
             .setBody("Hallo Welt!"));