When making a call to my Rest API's endpoint, I am taking into account that it may end up in an exception thrown.
For example, I've got an endpoint GET /api/entity?name=${some_name}
. Suppose that there's no entity of name XYZ
. In that case, when someone makes a request GET /api/entity?name=XYZ
, my service will throw EntityNotFoundException
- a custom exception class I've made.
This is how such request looks like:
public void apiCall() {
webClient.method(HttpMethod.GET)
.uri(uriBuilder -> uriBuilder
.path("/api/entity")
.queryParam("name", "XYZ")
.build()
).retrieve()
.bodyToMono(MyCustomClass.class)
.block();
}
The above call will throw WebClientResponseException
. All I really need is the underlying exception that is thrown in EntityService
and is called EntityNotFoundException
. How do I retrieve my custom exception?