Search code examples
androidandroid-volleyhttp-status-codes

how to handle statuscode in android studio?


I am using volley liabrary for the login. After entered wrong password progressDialog is keep running until I kill the app. And one toast message is displaying(System Generated) that unauthorized user 401 statusCode. I dont understand how to handle this condition?


Solution

  • new Response.ErrorListener() {

    @Override
    public void onErrorResponse(VolleyError error) {
    
        Log.e("Volly Error", error.toString());
        // Dismiss progress dialog here
    
        NetworkResponse networkResponse = error.networkResponse;
        if (networkResponse != null && networkResponse.statusCode == 401) {
            // Put your code here to handle this specific error code
        }
    }
    

    }