When using Observables with Retrofit how do you handle Network failure?
Given this code:
Observable observable = api.getApiService(
As of Retrofit2
and RxJava2
there is no more RetrofitError
exception. And its successor HttpException
only represents HTTP error response codes. Network errors should be handled through IOException
.
@Override
public void onError(Throwable e) {
if (e instanceof IOException) {
//handle network error
} else if (e instanceof HttpException) {
//handle HTTP error response code
} else {
//handle other exceptions
}
}