{"id":7727,"date":"2015-10-19T01:11:50","date_gmt":"2015-10-19T01:11:50","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/19\/how-do-i-get-robospice-to-treat-anything-other-than-a-200-response-from-retrofit-okhttp-as-an-error-open-source-projects-square-okhttp\/"},"modified":"2015-10-19T01:11:50","modified_gmt":"2015-10-19T01:11:50","slug":"how-do-i-get-robospice-to-treat-anything-other-than-a-200-response-from-retrofit-okhttp-as-an-error-open-source-projects-square-okhttp","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/19\/how-do-i-get-robospice-to-treat-anything-other-than-a-200-response-from-retrofit-okhttp-as-an-error-open-source-projects-square-okhttp\/","title":{"rendered":"How do I get Robospice to treat anything other than a 200 response from Retrofit &#038; OKHttp as an error-open source projects square\/okhttp"},"content":{"rendered":"<p>I am using Robospice on android with Retrofit and OKHttp. All works great with responses passed back to the activity using the Robospice RequestListener. The problem is that it only returns a failure if the connection times out or another network issue. If a 401 is returned then it is classed as a success but with a null response as it couldn&#8217;t parse the JSON into our MobileAppSetup POJO.<\/p>\n<p>At the moment I&#8217;m having to do null checking on the response but I have no idea what the reason was if it was a server error or a valid 401.<\/p>\n<pre><code>public final class HTTPRequestListener implements RequestListener {\n\n    @Override\n    public void onRequestFailure(SpiceException spiceException) {\n        Log.d(\"\", \"failure:\"+ spiceException);\n        loginProgress.hide();\n\n    }\n\n    @Override\n    public void onRequestSuccess(final MobileAppSetup response) {\n        Log.d(\"\",\"success. Data: \"+response);\n\n        if(response==null)\n            showDialog(\"Error logging in\", \"Please check your username and password and try again.\", \"\");\n\n        loginProgress.hide();\n\n        postLoginProcess(response);\n\n    }\n} \n<\/code><\/pre>\n<p>I need to pass these errors to the onRequestFailure callback so I can properly handle it. Is there a way to specify error codes that Robospice should treat as an error. I think it involves adding some kind of custom error handler but really can&#8217;t find a solution at the moment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am using Robospice on android with Retrofit and OKHttp. All works great with responses passed back to the activity using the Robospice RequestListener. The problem is that it only returns a failure if the connection times out or another network issue. If a 401 is returned then it is classed as a success but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7727","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7727"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7727\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}