WIP: WebClient
authorKai Moritz <kai@jupl.de>
Thu, 21 Nov 2019 15:55:29 +0000 (16:55 +0100)
committerKai Moritz <kai@jupl.de>
Thu, 21 Nov 2019 15:55:29 +0000 (16:55 +0100)
src/main/java/de/juplo/facebook/errors/GraphApiException.java

index 27f359f..ce3836c 100644 (file)
@@ -49,15 +49,10 @@ public class GraphApiException extends RuntimeException
 
   public static Mono<GraphApiException> create(ClientResponse response)
   {
-               return DataBufferUtils.join(response.body(BodyExtractors.toDataBuffers()))
-                               .map(dataBuffer -> {
-                                       byte[] bytes = new byte[dataBuffer.readableByteCount()];
-                                       dataBuffer.read(bytes);
-                                       DataBufferUtils.release(dataBuffer);
-                                       return bytes;
-                               })
-                               .defaultIfEmpty(new byte[0])
-                               .map(bytes -> create(response.statusCode(), response.headers().asHttpHeaders(), bytes));
+    return
+        response
+            .createException()
+            .map(we -> create(response.statusCode(), response.headers().asHttpHeaders(), we.getResponseBodyAsByteArray()));
   }
 
   public static GraphApiException create(