Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    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

    #2
    Hi Isomorphic,

    Please provide a reply for this.
    Thanks

    Comment


      #3
      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

      Comment

      Working...
      X