Skip to content Skip to sidebar Skip to footer

How To Add Retrywhen() For Limited Time (eg 3 Time Retries Only) Getting Ioexception

I am fetching response from server using 3 web API calls, but in case of getting IOException i have to retry those calls for 3 times using retryWhen(). How can I achieve that? i ha

Solution 1:

There's a version of retry that calls a predicate to determine if the stream should be subscribed or not - if you should retry. The predicate receives 2 arguments - number of attempts and the throwable. It seems to be what you want. I'd try:

observableThatMightError
   .retry((count, throwable) -> throwableinstanceof IOExceptio && count <= 3)

this will retry if the throwable is an IOException and you haven't retried yet for at least 3 times.

Post a Comment for "How To Add Retrywhen() For Limited Time (eg 3 Time Retries Only) Getting Ioexception"