+package de.juplo.facebook.errors;
+
+
+import org.springframework.http.HttpStatus;
+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 reactor.core.publisher.Mono;
+
+
+/**
+ * An {@link ExchangeFilterFunction}
+ * @author Kai Moritz
+ */
+public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction
+{
+ public static GraphApiExchangeFilterFunction INSTANCE =
+ new GraphApiExchangeFilterFunction();
+
+
+ @Override
+ public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next)
+ {
+ return
+ next
+ .exchange(request)
+ .flatMap(response ->
+ {
+ return
+ HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series())
+ ? Mono.error(GraphApiException.create(response))
+ : Mono.just(response);
+ });
+ }
+}