Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Proper reponse for exception during ajax/xml/json request

 
r vertet
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But for an exception would 500 be most appropriate?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic