Reputation: 2706
So I have the following piece of code to do a GET to a remote machine:
webClient.get()
.uri(myUri)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(String.class)
.subscribe(text -> {
LOG.info(text);
});
I get this exception, no problem, I'm expecting it, but it's really hard to find any documentation how to handle these errors:
reactor.core.Exceptions$ErrorCallbackNotImplemented: java.net.UnknownHostException
Upvotes: 7
Views: 14644
Reputation: 2706
To handle these exceptions you need to add the following, adapt it to your case (in my case if I get an unkownHostException I simply log a warning that the requested service is not present:
webClient.get()
.uri(myUri)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(String.class)
.onErrorResume(e -> {
if (e instanceof UnknownHostException) {
LOG.warn("Failed to get myStuff, desired service not present");
} else {
LOG.error("Failed to get myStuff");
}
return Mono.just("Encountered an exception");
})
.subscribe(text -> {
LOG.info(text);
});
You handle the error, and send something to the next step. I really wish there was a way to stop there and not pass anything down the pipe.
Upvotes: 9