Handle Network error with Retrofit observable

前端 未结 4 2129
失恋的感觉
失恋的感觉 2021-02-18 13:13

When using Observables with Retrofit how do you handle Network failure?

Given this code:

Observable observable = api.getApiService(         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-18 13:58

    Note that if you let an observable emit onError, all upstream observables will shut down - regardless of whether you "catch" it with onErrorReturn or onErrorResumeNext. Often you don't want that. For example, if your stream starts with a button click that triggers a retrofit request which fails, then the button clicks won't be recognized anymore since the stream terminated.

    Use Observable> or Observable> to also handle retrofit errors in onNext().

    s. http://blog.danlew.net/2015/12/08/error-handling-in-rxjava/

提交回复
热议问题