Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

The correct way to retry api request,when network fail.

Open ltthuc1989 opened this issue 9 years ago • 2 comments

Hi,amitshekhariitbhu While calling api request,Sometime network fail.So i want to recall current request .Could you tell me what correct way to retry current request.This is my code which use to recall current request.Thank so much @Override public void upload(final VideoRequest request) { getMvpView().showUploading(); getCompositeDisposable().add(getDataManager() .doUploadVideo(request) ........ }, new Consumer() { @Override public void accept(Throwable throwable) throws Exception { if (!isViewAttached()) { return; } getMvpView().hideUploading(); if (throwable instanceof ANError) { ANError anError = (ANError) throwable; if (anError.getErrorCode() == AppConstants.API_STATUS_CODE_LOCAL_ERROR && anError.getErrorDetail().equals(ANConstants.CONNECTION_ERROR)) { getMvpView().showCancelRetryAlert(R.string.connection_error, new CancelRetryCallback() { @Override public void onCancel() { } @Override public void onRetry() { upload(request); } }); } else { handleApiError(anError); } } } })); }

ltthuc1989 avatar May 19 '17 03:05 ltthuc1989

The best way will be by using retry operator of RxJava. Refer this link

amitshekhariitbhu avatar May 19 '17 03:05 amitshekhariitbhu

Thank for your good support ! @amitshekhariitbhu

ltthuc1989 avatar May 19 '17 04:05 ltthuc1989