Announcement

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

    How to intercept JSON format error

    SmartGWTPro 3.1p
    GWT 2.5.0

    I am using a ListGrid with datasource using JSON format. In our case, the data coming back from the URL can be non-JSON, e.g. when the HTTP session expired, for that I want to handle it differently.

    I want to intercept the data before the datasource parse the data into JSON, can you please instruct me on how to accomplish that?

    I have tried overwriting transformResponse() of DataSource class. When format is JSON, I am not sure how to interpret the 'data' parameter. When format is CUSTOM, 'data' is the raw String data, but doing a super.transformResponse() does not seem to format the data into ListGridFields. Please help.

    #2
    Hi wlam
    You have a couple of options here:
    - if the protocol is declared as JSON, then then any errors
    should be delivered as JSON and not in any other format. For
    catastrophic errors, you could use an HTTP error code so it becomes a transport error and handleTransparentError fires.
    - alternatively, if you want to use non-JSON responses to signal ordinary errors (like validation failures, for example) then you indeed should use the "custom" format, because you are not really using JSON. You can then write your own logic into transform response to handle whatever format you get back, including parsing JSON text into live JavaScript objects

    Regards
    Isomorphic Software

    Comment


      #3
      option 1 is kind of hard in our existing architecture.

      Can you point me to any samples or classes/methods related to 'parsing JSON text into live JavaScript objects' ? Should those be part of ListGrid.transformResponse() implementation?

      Thanks.

      Comment


        #4
        Standard techniques apply - you can use our JSON.decode() helper method, or any JSON library compatible with GWT.

        Comment

        Working...
        X