</dependency>
<dependency>
<groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
+ <artifactId>spring-webflux</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
+import org.springframework.http.ReactiveHttpInputMessage;
+import org.springframework.web.reactive.function.BodyExtractor.Context;
+import org.springframework.web.reactive.function.client.ClientResponse;
}
+
+ public static GraphApiException create(ClientResponse response)
+ {
+ return
+ response.body((ReactiveHttpInputMessage message, Context context) ->
+ {
+ DataBuffer buffer = message.getBody().blockFirst();
+ InputStream is = message.getBody().blockFirst().asInputStream();
+ return create(response.statusCode(), message.getHeaders(), is);
+ });
+ }
+
public static GraphApiException create(
HttpStatus status,
HttpHeaders headers,
--- /dev/null
+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);
+ });
+ }
+}