androidandroid-volleyandroidhttpclient

Getting response code from volley error response


How do we get response code and message of an errenous response from client? Here error.toString() returns: com.android.volley.ServerError error.getMEssage(): null error.getCause(): null parseNetworkResponse: never ever enters that function. When I add getParams() method, it may return ClientError but response code etc still doesnt work!!!!!!! I am trying this for the last 24 hours. No answer on anywhere.

private void getStudentInfo(String number){
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
final String url = organizationRoot+"/identity/detailed/" +number ;
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        txtTagContent.setText(response);
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {

        txtTagContent.setText("ERROR " + error.toString() + error.getMessage() + error.getCause());
    }
}){

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        return requestHeaders;
    }

    @Override
    protected Response<String> parseNetworkResponse(NetworkResponse response) {
            txtTagContent.setText("WORKED ");
            return Response.success( "", HttpHeaderParser.parseCacheHeaders(response));
    }
};
requestQueue.add(stringRequest);

}


Solution

  • Could you try:

    int statusCode = error.networkResponse.statusCode;
    Log.e(TAG, String.valueOf(statusCode);