Struggling to figure out how to take an exception received from a reactive request and just bubble it up (body and Http Status Code would be the minimum information).
I was hoping to use ExchangeFilterFunction as mentioned here but can't seem to have the error caught. I know it is registered and running through the method
public class MyExchangeFilterFunction implements ExchangeFilterFunction {
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
return next.exchange(request).onErrorMap(MyError.class, c -> new RuntimeException("Ow"));
}
}
Register the filter function:
WebClient.builder().filter(new MyExchangeFilterFunction())...
Error to transform into (since I can't figure out how to just bubble up):
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class MyError extends RuntimeException{
private Long timestamp;
private String path;
private Integer status;
private String error;
private String message;
}
--------Update-------
Error is now being tossed with the latest code, but unable to figure out how to jam the response body into a Flux/Mono Error.
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
return next.exchange(request).map(cr -> {
if(cr.statusCode().isError()) {
return ClientResponse.from(cr).body(
Flux.error(new RuntimeException("OW"))
).build();
} else {
return cr;
}
});
}