Spring has introduced the new HTTP interface. For exception handling the documentation states to register a response status handler that applies to all responses performed through the client:
WebClient webClient = WebClient.builder()
.defaultStatusHandler(HttpStatusCode::isError, resp -> ...)
.build();
However, it's not clear how to handle retries.
In WebClient you could simple use retryWhen():
public Mono<String> getData(String stockId) {
return webClient.get()
.uri(PATH_BY_ID, stockId)
.retrieve()
.bodyToMono(String.class)
.retryWhen(Retry.backoff(3, Duration.ofSeconds(2)));
}
I'm not sure how to incorporate retries with the Http interfaces.