Custom Retrofit ErrorHandler gives UndeclaredThrowableException

谁说胖子不能爱 提交于 2019-12-30 06:25:10

问题


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.


回答1:


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

interface MyService {
  Foo doFoo() throws MyNetworkError;
}


来源:https://stackoverflow.com/questions/24615437/custom-retrofit-errorhandler-gives-undeclaredthrowableexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!