Skip to content Skip to sidebar Skip to footer

How To Deal With Unexpected Response 500 In Android

I am trying to retrieve a JSON from an external API using Volley. Here is my code protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

Solution 1:

HTTP Status Codes starting with 5 inform that the error is on server side. The code 500 is interpreted as Internal Server Error, to solve this you have to check what might cause it. It may be caused by a mistake in the code in that case you can open your error_log to see the error and act accordingly.

It can be caused by server features being unavailable momently like accessing the database or having many simultaneous opened connections that exceed the associated mysql resources.

Some other times, the error is not logged into the error_log file. If you use a cpanel, at the homepage, under Metrics tab open Errors and check according to the time you requested to the server. If you are not using cpanel look for a corresponding server log.

With the link passed in your question that error code should not be unless it's overwritten or hardcoded in your server side script.

See these three tests:

enter image description here

With this, I set both time and cancer parameters, and as you can see, the Error Code is 500 but within the response body, every thing is okay with status 200.

enter image description here

And with this, I still have the answer even if I just set one parameter. within the response body, there is an error not server error but customized error: there is a parameter missing. Guess what's the returned HTTP code(500)

And what if I remove all parameters?

enter image description here

Every thing is okay. The HTTP Status Code and response body. That tells me that wether the author wants you to listen to customized request status rather than the returned HTTP Status Code. That's just my point of view.

Solution 2:

I found a Bug on API you are using is sending response code 500 + Response Data. And in volley whenever response code other then 200 to 299 is detected volley run there Error Listeners to handle it. That's why your code missed your Response data because Volley Error Listener get Call First.

Postman Picture mark with both Points

Frankly saying this is Nonstandard Poor Way of API Designing, which throwing status code on Responses as well.

Too things i want to tell you :

  1. Start using Postman (If you are not using it)

  2. Jamun Volley Library

start using helper libraries this is what i recommend you to Use which handle your most methods call and provide you better error handling with custom messages and individual status codes.

Hope this will help you to tackle future approaches.

Post a Comment for "How To Deal With Unexpected Response 500 In Android"