Is there anyway to retry a retrofit http request when network connection available with Rx-java?
This is my request method
public DisposableObserver<List<Photo>> getNewPhotos(final int page,
int perPage,
String orderBy,
ObservableTransformer<List<Photo>, List<Photo>> observableTransformer,
final Callback<List<Photo>> callBack) {
return photoService.getPhotos(page, perPage, orderBy)
.compose(observableTransformer)
.retryWhen(new Function<Observable<Throwable>, ObservableSource<?>>() {
@Override
public ObservableSource<?> apply(Observable<Throwable> throwableObservable) throws Exception {
return null;
}
})
.onErrorResumeNext(new Function<Throwable, ObservableSource<? extends List<Photo>>>() {
@Override
public ObservableSource<? extends List<Photo>> apply(Throwable throwable) throws Exception {
return Observable.error(throwable);
}
})
.subscribeWith(new DisposableObserver<List<Photo>>() {
@Override
public void onNext(List<Photo> value) {
callBack.onSuccess(value);
}
@Override
public void onError(Throwable e) {
callBack.onError(new NetworkError(e));
}
@Override
public void onComplete() {
}
});
}
i think maybe i could do something in retryWhen() method. i want retrofit to trigger for internet connection and retry the last request when the connection is back. i know the traditional way to retry but i think there must be a method or something in Rx-java to handle this. if someone knows its good to share it with me.