WIP: WebClient
[facebook-errors] / src / main / java / de / juplo / facebook / errors / GraphApiExchangeFilterFunction.java
index 6642e38..6ab18b6 100644 (file)
@@ -1,8 +1,6 @@
 package de.juplo.facebook.errors;
 
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.reactive.function.client.ClientRequest;
 import org.springframework.web.reactive.function.client.ClientResponse;
@@ -17,25 +15,23 @@ import reactor.core.publisher.Mono;
  */
 public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction
 {
-  private static final Logger LOG =
-      LoggerFactory.getLogger(GraphApiExchangeFilterFunction.class);
-
-  public static GraphApiExchangeFilterFunction INSTANCE =
-      new GraphApiExchangeFilterFunction();
-
-
   @Override
   public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next)
   {
     return
         next
             .exchange(request)
-            .doOnError(e -> LOG.debug("ERROR: {}", e))
             .flatMap(response ->
             {
               return
                   HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series())
-                      ? Mono.error(GraphApiException.create(response).block())
+                      ? response
+                          .bodyToMono(String.class)
+                          .map(errorBody -> GraphApiException.create(
+                              response.statusCode(),
+                              response.headers().asHttpHeaders(),
+                              errorBody.getBytes()))
+                          .flatMap(e -> Mono.error(e))
                       : Mono.just(response);
             });
   }