I have RestController, which returns Mono. And if i catch TimeoutException, i need log it and return my custom ErrorResponse. Now, it works and looks like this:
return service.someMethod(phone, ctx)
.doOnNext(resp -> log("done")
.timeout(timeout)
.doOnError(TimeoutException.class, e -> log.error(ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR + e.getLocalizedMessage()))
.onErrorResume(TimeoutException.class, e -> Mono.just(new MyCustomWrapper<>(
new MyCustomError("EIPbXsxiuA" , ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR))
);
I want to combine doOnError and onErrorResume. How can i do this?
>Solution :
How about removing doOnError and put the logging inside onErrorResume like this:
return service.someMethod(phone, ctx)
.doOnNext(resp -> log("done")
.timeout(timeout)
.onErrorResume(TimeoutException.class, e -> {
log.error(ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR + e.getLocalizedMessage())
Mono.just(new MyCustomWrapper<>(
new MyCustomError("EIPbXsxiuA" , ServiceErrors.CLIENT_SEARCH_TIMEOUT_ERROR))
});