Nav
Nav

Reputation: 435

Parsing volley Error

In the app, I am using

parseNetworkError(VolleyError volleyError)

method to parse the error. Everything is working fine and I ma getting the parsed error. However, the problem is the error comes in this manner

com.android.volley.VolleyError: "THE ACTUAL MESSAGE I NEED"

I could not figure out how to get only "THE ACTUAL MESSAGE I NEED" from the entire error message.

Here is the method implementation:

@Override
protected VolleyError parseNetworkError(VolleyError volleyError)
{
  if(volleyError.networkResponse != null && volleyError.networkResponse.data != null)
  {
      VolleyError error = new VolleyError(new String(volleyError.networkResponse.data));
      volleyError = error;
      System.out.println("volley error"+volleyError);
  }
  return volleyError;
}

The one thing which I am thinking of is that I can use split(":") method. But I want to know if there is any other method available.

Upvotes: 0

Views: 1225

Answers (1)

Prince Bansal
Prince Bansal

Reputation: 1655

You could try one of the following:

@Override
protected VolleyError parseNetworkError(VolleyError volleyError)
{
  if(volleyError.networkResponse != null && volleyError.networkResponse.data != null)
  {

      System.out.println("volley error"+volleyError.getMessage());
      //OR
      System.out.println("volley error"+volleyError.getLocalizedMessage());
      //OR
      System.out.println("volley error"+volleyError.getCause().getMessage());
      //OR
      System.out.println("volley error"+volleyError.getLocalizedMessage());
      //Or if nothing works than splitting is the only option
      System.out.println("volley error"+new String(volleyError.networkResponse.data).split(":")[1]);
  }
  return volleyError;
}

Upvotes: 3

Related Questions