Before I am using Volley, well as usual, I used AsyncTask to check my internet state.
Here is what I did in AsyncTask:
private class NetCheck extends
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
if (volleyError instanceof TimeoutError || volleyError instanceof NoConnectionError) {
Toast.makeText(getApplicationContext(), "No Connection/Communication Error!", Toast.LENGTH_SHORT).show();
} else if (volleyError instanceof AuthFailureError) {
Toast.makeText(getApplicationContext(), "Authentication/ Auth Error!", Toast.LENGTH_SHORT).show();
} else if (volleyError instanceof ServerError) {
Toast.makeText(getApplicationContext(), "Server Error!", Toast.LENGTH_SHORT).show();
} else if (volleyError instanceof NetworkError) {
Toast.makeText(getApplicationContext(), "Network Error!", Toast.LENGTH_SHORT).show();
} else if (volleyError instanceof ParseError) {
Toast.makeText(getApplicationContext(), "Parse Error!", Toast.LENGTH_SHORT).show();
}
}
});
This is good for you as a developer. But do not show some of this direct messages like auth and server-side error to the end user. Be creative and show something like can not connect at the moment.