Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJava observable: Invoke onError and then retry

Tags:

rx-java

I'm currently using retry() to re-subscribe to my Observable if an error occurs. In this way my Subscriber's onError is not called: there is a way to let onError be called and THEN re-subscribe to the Observable?

like image 541
brescia123 Avatar asked Jan 25 '26 09:01

brescia123


1 Answers

By the Observable Contract If you invoke onError then your observable will not emit any more items. For this reason alone I do not think that you should try implement it this way(allowing the error to propagate to the subscriber).

If you want to execute any action upon an error then try to use doOnError() before retry().

So your code could look like this:

getObservableThatMaybeEmitsTheError()
    .doOnError(throwable -> LogTheErrorMethod(throwable))
    .retry()
    ...
    .subscribe()
like image 150
MatBos Avatar answered Jan 26 '26 23:01

MatBos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!