brescia123
brescia123

Reputation: 517

RxJava observable: Invoke onError and then retry

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?

Upvotes: 3

Views: 1038

Answers (1)

MatBos
MatBos

Reputation: 2390

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()

Upvotes: 8

Related Questions