android - volley error No authentication challenges found

后端 未结 5 1886
遇见更好的自我
遇见更好的自我 2020-12-16 17:41

I am trying to work with some legacy code and have come up against an issue when using volley.

I am trying to get to an api that our main site has and it works fine

5条回答
  •  既然无缘
    2020-12-16 18:15

    I was able to catch this client-side when initializing the volley RequestQueue:

    Volley.newRequestQueue(getApplicationContext(), new HurlStack() {
            @Override
            public HttpResponse performRequest(Request request, Map additionalHeaders) {
                try {
                    return super.performRequest(request, additionalHeaders);
                } catch (AuthFailureError authFailureError) {
                    authFailureError.printStackTrace();
                    // Log out / whatever you need to do here
                } catch (IOException e) {
                    e.printStackTrace();
                    if (e.getMessage().equals("No authentication challenges found")) {
                        // This is the error.  You probably will want to handle any IOException, not just those with the same message.
                    }
                }
                return null;
            }
    });
    

提交回复
热议问题