Skip to content

Instantly share code, notes, and snippets.

@ragdroid
Created September 7, 2016 21:37
Show Gist options
  • Save ragdroid/4aa00ff7064794a9651cc23580a80961 to your computer and use it in GitHub Desktop.
Save ragdroid/4aa00ff7064794a9651cc23580a80961 to your computer and use it in GitHub Desktop.
Retry when IOException example DroidconIN 2016
//Retry when IOException
Observable<UserResponse> getUserFromServer() {
return userService.getUserFromServer()
.retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() {
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
return observable.flatMap(new Func1<Throwable, Observable<?>>() {
@Override
public Observable<?> call(Throwable throwable) {
if (throwable instanceof IOException) {
//retry only when we get no internet IOException
return Observable.just(null);
}
return Observable.error(throwable);
}
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment