Go Back   SmartClient Forums > Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14th Apr 2011, 02:59
sabhinandan sabhinandan is offline
Registered Developer
 
Join Date: Sep 2010
Posts: 17
Default Unexpected response in RESTDatasource

Hi,

I am using a RESTDatasource that get data from a sevlets in json format,
and i need to handle situations where response that this datasource gets is other than a json string, say a html page or a simple string.

I know that in situations where a auth system intercepts the ajax request and provides an html form can be handled using loginRequired marker, but for situations other than this where we dont know what response can come to this datasource how we can handle this , like in my case the static content is served by apache and dynamic content by tomcat, and in cases where tomcat is down but apache is up i can get a html error page, in this case transform response is never called and the gird attached to the datasource just keep displaying "loading data".

TIA
Reply With Quote
  #2  
Old 18th Apr 2011, 00:02
sabhinandan sabhinandan is offline
Registered Developer
 
Join Date: Sep 2010
Posts: 17
Default

Hi Isomorphic,

Please provide a reply for this.
Thanks
Reply With Quote
  #3  
Old 18th Apr 2011, 06:19
solstice solstice is offline
Registered Developer
 
Join Date: Mar 2011
Posts: 57
Default

In the event that a server-side exception occurs, Java development best practices say that you should catch the exception and return an appropriately formatted error message.

In your case, where you are returning a JSON string, you should be catching the exception and returning the ServletException.getMessage() value as part of the JSON object. In addition, you should also be returning a numeric error code (much easier for the client to parse and divine meaning), as well as changing the HTTP. Typically, the user should not be concerned with the technical details of the error message. This includes the stack trace but also the system-generated message. It's usually better to display a user-friendly message such as "We're sorry but your request cannot be completed at this time." or "An error has occurred and our technical support staff has been notified." Besides, what are they supposed to do with a Null Pointer Exception anyway? :) Your exception handling should have a notification mechanism in it that sends an email to tech support, or writes to a log file or similar, and that is where you should be including all of the technical details of the exception.

I guess this is a long-winded way of saying that you should not be relying on the error page generated by the web server and displaying that to your user. As you have found out, Javascript does not know how to deal with that when it is expecting a JSON object. That said, you can add an error handler to your DataSource and display the contents of the error page returned but it really isn't going to be doing your user any good. Here is the link to the relevant API: http://www.smartclient.com/docs/8.0/a/b/c/go.html#method..DataSource.handleError
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSON + RestDataSource aderraik Smart GWT Technical Q&A 2 6th Dec 2010 12:59
Grouped filtering patelk7 Smart GWT Technical Q&A 10 1st Sep 2010 05:11
ListGrid filtering issue krishnafse2009 Smart GWT Technical Q&A 5 26th Jul 2010 08:31
REST data source and HTTP response codes borice Smart GWT Technical Q&A 3 24th Nov 2009 05:00
setting status in restdatasource response jenis23 Technical Q&A 3 27th Feb 2009 00:03

© 2010,2011 Isomorphic Software. All Rights Reserved