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)
+ .flatMap(errorBody -> Mono.error(GraphApiException.create(
+ response.statusCode(),
+ response.headers().asHttpHeaders(),
+ errorBody.getBytes())))
: Mono.just(response);
});
}
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.reactive.JettyClientHttpConnector;
-import org.springframework.web.reactive.function.client.ClientRequest;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.ExchangeFunction;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
.builder()
.clientConnector(new JettyClientHttpConnector())
.baseUrl(server.url("/").toString())
- .filter(this::errorHandlingFilter)
+ .filter(GraphApiExchangeFilterFunction.INSTANCE)
.build();
}
.expectComplete()
.verify(Duration.ofSeconds(3));
}
-
- public Mono<ClientResponse> errorHandlingFilter(ClientRequest request, ExchangeFunction next)
- {
- return
- next
- .exchange(request)
- .flatMap(response ->
- {
- return
- HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series())
- ? response
- .bodyToMono(String.class)
- .flatMap(errorBody -> Mono.error(GraphApiException.create(
- response.statusCode(),
- response.headers().asHttpHeaders(),
- errorBody.getBytes())))
- : Mono.just(response);
- });
- }
}