How do I get Robospice to treat anything other than a 200 response from Retrofit & OKHttp as an error-open source projects square/okhttp
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’t parse the JSON into our MobileAppSetup POJO.
At the moment I’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.
public final class HTTPRequestListener implements RequestListener {
@Override
public void onRequestFailure(SpiceException spiceException) {
Log.d("", "failure:"+ spiceException);
loginProgress.hide();
}
@Override
public void onRequestSuccess(final MobileAppSetup response) {
Log.d("","success. Data: "+response);
if(response==null)
showDialog("Error logging in", "Please check your username and password and try again.", "");
loginProgress.hide();
postLoginProcess(response);
}
}
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’t find a solution at the moment.