WIP: WebClient
[facebook-errors] / src / main / java / de / juplo / facebook / errors / GraphApiExchangeFilterFunction.java
index 9bff65d..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;
 
 
@@ -27,10 +28,21 @@ public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction
                   HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series())
                       ? response
                           .bodyToMono(String.class)
-                          .flatMap(errorBody -> Mono.error(GraphApiException.create(
+                          .map(errorBody -> GraphApiException.create(
                               response.statusCode(),
                               response.headers().asHttpHeaders(),
-                              errorBody.getBytes())))
+                              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);
             });
   }