/** * Return a filter that generates an error signal when the given * {@link HttpStatus} predicate matches. * @param statusPredicate the predicate to check the HTTP status with * @param exceptionFunction the function that to create the exception * @return the filter to generate an error signal */ public static ExchangeFilterFunction statusError(Predicate<HttpStatus> statusPredicate, Function<ClientResponse, ? extends Throwable> exceptionFunction) { Assert.notNull(statusPredicate, "Predicate must not be null"); Assert.notNull(exceptionFunction, "Function must not be null"); return ExchangeFilterFunction.ofResponseProcessor( response -> (statusPredicate.test(response.statusCode()) ? Mono.error(exceptionFunction.apply(response)) : Mono.just(response))); }
@Test public void shouldApplyErrorHandlingFilter() { ExchangeFilterFunction filter = ExchangeFilterFunction.ofResponseProcessor( clientResponse -> { List<String> headerValues = clientResponse.headers().header("Foo");