I need to make another HTTP call in the case that my WebClient request receives a HTTP 4xx or 5xx error.
Currently I have the following:
webClient.post()
.uri(myUri)
.headers(myHeaders)
.body(myBody)
.retrieve()
.onStatus(HttpStatus::isError, responseStrategy::errorResponseCallback)
...
My error response callback looks like this:
public Mono<? extends Throwable> errorResponseCallback(ClientResponse clientResponse) {
... make ugly new HTTP request here
return Mono.error(...);
}
I don't like the idea of embedding error handling in the callback which is only supposed to return a Mono containing an exception.
What is the correct approach for this situation?