Based on this post How should I handle "No internet connection" with Retrofit on Android
I made a custom ErrorHandler
private static class CustomErrorHandler implements ErrorHandler {
@Override
public Throwable handleError(RetrofitError error) {
if (error.isNetworkError()) {
return new MyNetworkError();
}
return error.getCause();
}
}
And now my application crashes and I get this:
java.lang.reflect.UndeclaredThrowableException
Is there some configuration needed for the adapter? Using Retrofit 1.6.0
with OkHttp 2.0.0
Thanks.
If you are returning a checked exception you need to declare it on the interface.
interface MyService {
Foo doFoo() throws MyNetworkError;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With