Search code examples
androidandroid-volleyandroid-webservice

Volley error response bytes does not convert from bytes to string


CustomStringRequest customStringRequest = new CustomStringRequest(requestMethod.ordinal(), serverUrl,
            result -> {
                Log.d(TAG, "headers: " + result.headers);
                Log.d(TAG, "response: " + result.response);
                createTaskItem(result);
            },
            error -> {
                Log.d(TAG, "error: " + error);
            })

error is in JSON string, I tried to get error like this:

new String(error.networkResponse.data, "utf-8");
new String(error.networkResponse.data);

none of the above method works, i always get empty string, don't know why :(

enter image description here

as you can see bytes in picture, the error response is actually this:

   {
  "error": [
    "Wrong Credentials!"
  ],
  "email_exists": false
}

I am using:

implementation 'com.android.volley:volley:1.1.1'

Solution

  • oh, i was just evaluating error response in debug mode new String(error.networkResponse.data, "UTF-8"); and it returns empty string in result. I just tried to print error response and it worked!. Thanks.