How can I make Robospice treat anything other than 200 from Retrofit & OKHttp as an error

I am using Robospice for Android with retrofit and OKHttp. Everything works great with responses submitted to the action using Robospice RequestListener. The problem is that it only returns a failure if the connection time or other network problem. If 401 returns, then it is classified as successful, but with a null response, since it cannot parse JSON in our POJO MobileAppSetup.

At the moment, I need to perform a null response check, but I do not know what the reason is 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);

    }
} 

onRequestFailure, . , Robospice . , - , .

+4
1

​​ OKHTTP !

. 401, Callback fail().

401, RetrofitError null, networkError true, error.getResponse().getStatus() , http . OkClient : java.io.IOException:

okhttp jar square/okhttp ! okhttp.

+2

Source: https://habr.com/ru/post/1533328/


All Articles