7

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.

Community
  • 1
  • 1
Niko
  • 8,093
  • 5
  • 49
  • 85

1 Answers1

13

If you are returning a checked exception you need to declare it on the interface.

interface MyService {
  Foo doFoo() throws MyNetworkError;
}
Jake Wharton
  • 75,598
  • 23
  • 223
  • 230