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<MobileAppSetup> {
@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.
This due to the bug in OKHTTP client possible bug !
Problem is When the server answers with a 401 Unauthorized responses, the Callback object calls its failure() method..
When the server returns with the 401 status, the
RetrofitError
response object is null, and thenetworkError
flag is set to true, making it impossible for the app to checkerror.getResponse().getStatus()
I believe the error lies on the http client. When using OkClient I get this error: java.io.IOException: No authentication challenges found
I suggest you to download new okhttp jar file from square/okhttp run the project again! or try with any other client instead of okhttp.
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.