简体   繁体   中英

Android Retrofit - HTTP FAILED: java.net.UnknownHostException: Unable to resolve host {my base url}: No address associated with hostname

The project is using the latest retrofit version (2.3.0). If I turn off the internet connection on my phone or if no internet connection is available, retrofit is throwing a "HTTP FAILED" which is not caught by the onFailure() or onRespond(). This HTTP error is directed to the exception "Unable to resolve host (...)". I want to handle this error case in displaying a snackbar or something else. Currently I have no access to this exception and my loading screen will not stop due to not getting a respond message. Has anyone an idea how to solve that using retrofit?

The only working solution I found was to use interceptors checking every request if a internet connection is available. But there needs to be a better way to solve that issue, I hope.

It seems like my internal error handling was the problem. Retrofit is using the onFailure() to notify about HTTP FAILED (in version 2.3.0).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM