I use Retrofit as network library with Rx-Java. I want to make some centralized error checking for most requests and handle errors or pass it to subscriber's onError()
if I cannot handle it. How could I do this?
Something like this
projectListObservable
.subscribeOn(Schedulers.newThread())
.timeout(App.NETWORK_TIMEOUT_SEC, TimeUnit.SECONDS)
.retry(App.NETWORK_RETRY_COUNT)
.onError(e -> {
if (e instanseOf HttpError && ((HttpError)e).getCode == 403){
App.getInstance.getNetworkManager.reAuth();
} else {
throw(e);
}})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new ProjectListSubscriber());
Also, I should stop retrying in that case, but keep retry if it's a network problem (instanceof IOException
).