{"action":"created","issue":{"url":"https://api.github.com/repos/square/retrofit/issues/644","repository_url":"https://api.github.com/repos/square/retrofit","labels_url":"https://api.github.com/repos/square/retrofit/issues/644/labels{/name}","comments_url":"https://api.github.com/repos/square/retrofit/issues/644/comments","events_url":"https://api.github.com/repos/square/retrofit/issues/644/events","html_url":"https://github.com/square/retrofit/issues/644","id":47029273,"node_id":"MDU6SXNzdWU0NzAyOTI3Mw==","number":644,"title":"How to handle java.net.UnknownHostException while using retrofit","user":{"login":"leelei","id":8695231,"node_id":"MDQ6VXNlcjg2OTUyMzE=","avatar_url":"https://avatars1.githubusercontent.com/u/8695231?v=4","gravatar_id":"","url":"https://api.github.com/users/leelei","html_url":"https://github.com/leelei","followers_url":"https://api.github.com/users/leelei/followers","following_url":"https://api.github.com/users/leelei/following{/other_user}","gists_url":"https://api.github.com/users/leelei/gists{/gist_id}","starred_url":"https://api.github.com/users/leelei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leelei/subscriptions","organizations_url":"https://api.github.com/users/leelei/orgs","repos_url":"https://api.github.com/users/leelei/repos","events_url":"https://api.github.com/users/leelei/events{/privacy}","received_events_url":"https://api.github.com/users/leelei/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2014-10-28T14:03:51Z","updated_at":"2018-10-04T15:07:42Z","closed_at":"2014-10-28T16:56:46Z","author_association":"NONE","body":"I'm using retrofit to get and post data from the server. However, if my phone loses internet connection in middle of the app then I see error like this:\n\n<pre>\n java.net.UnknownHostException: Unable to resolve host \"api.weibo.com\": No address associated with hostname\n            at java.net.InetAddress.lookupHostByName(InetAddress.java:457)\n            at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)\n            at java.net.InetAddress.getAllByName(InetAddress.java:215)\n            at com.squareup.okhttp.internal.Dns$1.getAllByName(Dns.java:29)\n</pre>\n\nI would like to handle this error gracefully. I would like to catch the exception and show a toast message like \"No internet connection\".\n\n<pre>\n RestClient.get().getUser(\"uid\", new Callback<User>() {\n            @Override public void success(User user, Response response) {\n            }\n\n            @Override public void failure(RetrofitError error) {\n                // when connection not available , i want to show a toast\n                Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_SHORT).show();\n            }\n        });\n</pre>\n"},"comment":{"url":"https://api.github.com/repos/square/retrofit/issues/comments/427055140","html_url":"https://github.com/square/retrofit/issues/644#issuecomment-427055140","issue_url":"https://api.github.com/repos/square/retrofit/issues/644","id":427055140,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNzA1NTE0MA==","user":{"login":"johnnyfivedev","id":19605186,"node_id":"MDQ6VXNlcjE5NjA1MTg2","avatar_url":"https://avatars0.githubusercontent.com/u/19605186?v=4","gravatar_id":"","url":"https://api.github.com/users/johnnyfivedev","html_url":"https://github.com/johnnyfivedev","followers_url":"https://api.github.com/users/johnnyfivedev/followers","following_url":"https://api.github.com/users/johnnyfivedev/following{/other_user}","gists_url":"https://api.github.com/users/johnnyfivedev/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnyfivedev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnyfivedev/subscriptions","organizations_url":"https://api.github.com/users/johnnyfivedev/orgs","repos_url":"https://api.github.com/users/johnnyfivedev/repos","events_url":"https://api.github.com/users/johnnyfivedev/events{/privacy}","received_events_url":"https://api.github.com/users/johnnyfivedev/received_events","type":"User","site_admin":false},"created_at":"2018-10-04T15:07:42Z","updated_at":"2018-10-04T15:07:42Z","author_association":"NONE","body":"> onFailure() is not called\r\n\r\nSame thing. And this \"makes your life harder\".\r\n\r\n@JakeWharton any suggestions?"}}
{"actor":{"display_login":"johnnyfivedev"}}