WIP: WebClient
authorKai Moritz <kai@jupl.de>
Thu, 21 Nov 2019 14:28:19 +0000 (15:28 +0100)
committerKai Moritz <kai@jupl.de>
Thu, 21 Nov 2019 14:28:19 +0000 (15:28 +0100)
src/main/java/de/juplo/facebook/errors/GraphApiException.java
src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java
src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java

index 3f9c544..3ebc64f 100644 (file)
@@ -48,12 +48,14 @@ public class GraphApiException extends RuntimeException
 
 
 
-  public static GraphApiException create(ClientResponse response)
+  public static Mono<GraphApiException> create(ClientResponse response)
   {
     HttpStatus status = response.statusCode();
     HttpHeaders headers = response.headers().asHttpHeaders();
-    Mono<String> 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(
index 53bdd0b..6642e38 100644 (file)
@@ -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);
             });
   }
index c468590..b90e057 100644 (file)
@@ -103,7 +103,7 @@ public class GraphApiExchangeFilterFunctionIntegrationTest
             .filter((request, next) -> next.exchange(request).flatMap(response ->
             {
                                                        List<String> 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();