wood burning stoves 2.0*
The moose likes Web Services and the fly likes Proper reponse for exception during ajax/xml/json request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Proper reponse for exception during ajax/xml/json request" Watch "Proper reponse for exception during ajax/xml/json request" New topic
Author

Proper reponse for exception during ajax/xml/json request

r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Hi,

say, I have a webpage that sends some ajax-call to a http-server, expecting to return something like xml or json.

What would be the proper response when an exception would be thrown in the during the jsp-execution.

Sending a html-message saying "Oeps, some internal error has occured; please try later today again" is pretty useless when the response is evaluated by some machine.

Would it be proper to return a 500-http-response?
How can I signal the caller that I have failed?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
Of course it would be appropriate to return the correct response code - see javax.servlet.http.HttpServletResponse javadocs for a listing.

You can communicate a lot with a response code - for example it is important to distinguish between 404 and 500 errors.

Including appropriate text is the friendly thing to do - a machine call can evaluate the code and ignore the text.

Bill
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
But for an exception would 500 be most appropriate?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
If the discussion of response codes in the JavaDocs is not sufficient for you to decide which one to use, take a look at this rather nice Wikipedia page.

Bill
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Well, out of that list only the 500 would apply, but i would be rather generic compared to the other 5xx codes.

What is the general best practice in these cases?
What you normally return when a ajax/xml/json request fails server-side?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Proper reponse for exception during ajax/xml/json request