public Mono<ClientResponse> errorHandlingFilter(ClientRequest request, ExchangeFunction next)
{
- return next.exchange(request).flatMap(response ->
- {
- if (response.statusCode() != null && (response.statusCode()
- .is5xxServerError() || response.statusCode().is4xxClientError()))
- {
- return response.bodyToMono(String.class)
- .flatMap(errorBody ->
+ return
+ next
+ .exchange(request)
+ .flatMap(response ->
{
- return Mono.error(GraphApiException.create(response.statusCode(), response.headers().asHttpHeaders(), errorBody.getBytes()));
+ return
+ HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series())
+ ? response.bodyToMono(String.class).flatMap(errorBody ->
+ {
+ return Mono.error(GraphApiException.create(response.statusCode(), response.headers().asHttpHeaders(), errorBody.getBytes()));
+ })
+ : Mono.just(response);
});
- }
- else
- {
- return Mono.just(response);
- }
- });
}
}