Http Status Code in Android Volley when error.networkResponse is null

前端 未结 8 1155
忘了有多久
忘了有多久 2020-11-29 00:44

I am using Google Volley on the Android platform. I am having a problem in which the error parameter in onErrorResponse is returning a null n

8条回答
  •  醉酒成梦
    2020-11-29 00:47

    The error.networkResponse will be null, if the device has no network connection (you can proof this by enabling the airplane mode). Look at the corresponding code fragment from the Volley library.

    You have to check then, if the error is an instance of the NoConnectionError, before you look for the networkResponse. I cannot agree, that 401 error is not supported by Volley, I tested it and got a non-null networkResponse object back with 401 status code. Look at the corresponding code here.

提交回复
热议问题