T
T
Tsuzukeru2020-11-26 17:14:08
Android
Tsuzukeru, 2020-11-26 17:14:08

How to retry a method call on error using RxJava?

I'm learning RxJava. It is not possible to repeat the method call, which will contact the network and pull out a Json response.
The wideoInfoWrapper() method may fail, if this happens I need to perform certain actions and repeat the call to this method (n times). Can you tell me what methods and where to use?

fun getPlayingVideo(videoId: String){
        _networkState.set(NetworkState.LOADING)

        try{
            compositeDisposable.add(
                videoInfoWrapper(videoId)
                    .subscribeOn(Schedulers.io())
                    .subscribe ({
                        playingVideo.postValue(it)
                        _networkState.set(NetworkState.LOADED)
                        _networkState.set(NetworkState.WAITING)
                    },{
                        errorHandle(it)
                    })
            )
        }
        catch (e: Exception){
            Log.e("fetchVideos",e.message)
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-11-26
@Tsuzukeru

retry, retryWhen

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question