Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

doOnError and onErrorResume how to combine into one operator

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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))
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading