Handle Volley error

后端 未结 6 1214
[愿得一人]
[愿得一人] 2020-12-07 12:57

I want to handle and show some message in onErrorResponse

below is my code.

String url = MainActivity.strHostUrl+\"api/delete_picture\";         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 13:31

    Read more about Volley Error handling at Android Volley example with Error Handling

    Every Volley requests has two callbacks -one for success and one for failure.Based on the type of VolleyError parameter in the onErrorResponse callback developers can show a sensible message to the users as shown below

    @Override
    public void onErrorResponse (VolleyError error){
    
       if (error instanceof TimeoutError || error instanceof NoConnectionError) {
         //This indicates that the reuest has either time out or there is no connection
    
       } else if (error instanceof AuthFailureError) {
         // Error indicating that there was an Authentication Failure while performing the request
    
       } else if (error instanceof ServerError) {
         //Indicates that the server responded with a error response
    
       } else if (error instanceof NetworkError) {
         //Indicates that there was network error while performing the request
    
       } else if (error instanceof ParseError) {
          // Indicates that the server response could not be parsed
    
       }
    }
    

提交回复
热议问题