Closed DASAR-zz closed 8 years ago
You cannot avoid it. On flaky networks, Wi-Fis that require sign in, and other similar cases you won't be able to resolve DNS. All IOException
subclasses need handled by your application layer since networks are inherently unreliable to work 100% of the time.
I just ran into this testing my app in Airplane mode. I was surprised, since I'm using RxJava2 and have an onError handler. That handler does get hit, but then the app crashes immediately afterwards. What am I missing?
If it's useful, this is how I create my retrofit service:
private <T> T createService(String endpoint, Class<T> serviceClass, OkHttpClient okClient) {
RxJava2CallAdapterFactory rxAdapter = RxJava2CallAdapterFactory.createWithScheduler(RxUtil.ioScheduler);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(endpoint)
.client(okClient) // base client plus some interceptors for logging/header/useragent
.addCallAdapterFactory(rxAdapter)
.addConverterFactory(GsonAdapterFactory.gsonConverterFactory())
.build();
return retrofit.create(serviceClass);
}
@autonomousapps We have exactly the same scenario. RxJava2 with onError handler, but the exception is crashing the app. Did you get anywhere with this?
@bobtune I haven't seen the error for a few days, but I'm in the middle of an incremental rollout of the latest version of my app (and maybe I've been lucky). Since encountering this, this is what I've done to try to prevent further crashes:
Flowable<Response<Thing>>
to Flowable<Result<Thing>>
. I feel like this shouldn't matter, given the javadoc on Response
saying it passes IOException onto the onError handler, but I tried anyway. Result
gives us direct access to Throwables.com.jakewharton
package. Now I'm using this version:compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
For good measure, here are all my related dependencies:
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
compile 'com.squareup.okio:okio:1.11.0'
I saw in Fabric (Crashlitics) crash caused by UnknownHostException from okhttp3.Dns$1.lookup
Here crash report from Fabric: http://crashes.to/s/faa5cfd3554
What I can do to prevent this issue?