WIP: WebClient
[facebook-errors] / src / main / java / de / juplo / facebook / errors / GraphApiExchangeFilterFunction.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);
             });