@Override public void deliverError(VolleyError error) { super.deliverError(error); if (mListenerReference != null && mListenerReference.get() != null) { NetworkListener listener = mListenerReference.get(); BaseError response = new BaseError(); if (error.networkResponse != null) { response.mStatusCode = error.networkResponse.statusCode; response.mErrorMessage = new String(error.networkResponse.data); } else if (error instanceof NetworkError || error instanceof NoConnectionError) { response.mErrorMessage = "Please check the internet connection"; } else if (error instanceof TimeoutError) { response.mErrorMessage = "Server is busy try again later"; } else if (error instanceof AuthFailureError) { response.mErrorMessage = "Auth Failure"; } else if (error instanceof ServerError) { response.mErrorMessage = "ServerError"; } else if (error instanceof ParseError) { response.mErrorMessage = "Error in parsing server data"; } listener.onError(response); } }
private static void dispatchToQueue(Request pRequest, Context pContext) { if (!isNetworkConnected(pContext) && pRequest.getMethod() != Request.Method.GET) { // non-GET request should not return cached response in case of no network pRequest.deliverError(new VolleyError(RESPONSE_NO_INTERNET)); return; } switch (pRequest.getMethod()) { case Request.Method.POST: { pRequest.setRetryPolicy(RETRY_POLICY_POST); break; } case Request.Method.GET: default: { pRequest.setRetryPolicy(RETRY_POLICY_GET); break; } } mRequestQueue.add(pRequest); }