Mordag Mordag - 8 months ago 137
HTTP Question

Android Retrofit - HTTP FAILED: 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.

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download