How about exception handling in volley, does it provide exception handling mechanism in build or we need to handle it separately?
1 Answers
when you create a request object in Volley
you need to specify an error listener, Volley invokes the onErrorResponse
callback method of that listener passing an instance of the VolleyError
object when there is an error while performing the request.
The following is the list of exceptions in Volley:
AuthFailureError
— If you are trying to do Http Basic authentication then this error is most likely to come.
NetworkError
— Socket disconnection, server down, DNS issues might result in this error.
NoConnectionError
— Similar to NetworkError, but fires when the device does not have Internet connection, your error handling logic can club NetworkError
and NoConnectionError
together and treat them similarly.
ParseError
— While using JsonObjectRequest
or JsonArrayRequest
if the received JSON is malformed then this exception will be generated. If you get this error then it is a problem that should be fixed instead of being handled.
ServerError
— The server responded with an error, most likely with 4xx or 5xx HTTP status codes.
TimeoutError
— Socket timeout, either server is too busy to handle the request or there is some network latency issue. By default, Volley
times out the request after 2.5 seconds, use a RetryPolicy if you are consistently getting this error.
Source: http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/
-
It means we need to handle it separately.? – Vishwanath.M Apr 02 '15 at 17:14
-
Volley itself handled exception. If you want to customize those exception you can catch exception onErrorResponse method. – Sathish Apr 02 '15 at 17:26
-
If my response make you understand. Accept my answer. – Sathish Apr 02 '15 at 17:34
-
hey @Sathish, _Volley times out the request after 2.5 seconds_? I thought it was 5 sec. http://stackoverflow.com/a/22169775/6561141 – mrtpk Oct 02 '16 at 09:24