Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Where to trap Store / Proxy exception?

  1. #1
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710

    Default Where to trap Store / Proxy exception?

    Having a heck of time trying to find out where to trap an exception when the server returns a JSON object that has a root success property set to false, object returned look like:

    Code:
    {"success":false,"Message":"The remote server returned an error: (500) Internal Server Error."}
    I have a DataView configured with a Store and a Proxy to return a JSON object collection. Everything works great so long as the collection object is populated successfully. When there is an error on the server, I am creating and returning the above JSON object (which I can verify in the XHR request for Chrome), but the "load" listener on the store no longer handles the returned error object. I have tried listening to "exception" on the reader and proxy, how/where do I handle this request error?

    Thanks.

  2. #2
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710

    Default

    Ok, apparently if the reader is setup with "root" object, you need to ensure that your returned object includes that node or you get an error in the readRecords method Ext.data.Reader. This seems a little odd to me though, why not check the "success" property of the passed in object first, before trying to do a getRoot()? That way, I can return the simple error JSON object with a success: false rather than having to return the full but empty root object?

    Sencha code:
    Code:
       readRecords: function (data) {
          /**
          * The raw data object that was last passed to readRecords. Stored for further processing if needed
          * @property rawData
          * @type Mixed
          */
          this.rawData = data;
    
          data = this.getData(data);
    
          var root = this.getRoot(data),
                total = root.length,
                success = true,
                value, records, recordCount;
    
          if (this.totalProperty) {
             value = parseInt(this.getTotal(data), 10);
             if (!isNaN(value)) {
                total = value;
             }
          }
    
          if (this.successProperty) {           <---  Why not move this above the getRoot() and return if false?  Just a thought...
             value = this.getSuccess(data);
             if (value === false || value === 'false') {
                success = false;
             }
          }
          ........

  3. #3
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    48

    Default

    hi

    I've exactly the same setup and I've the same "problems".
    Where do I catch the exceptions?!?

    All HTTP error exceptions (e.g. return code 404) can be handled by the fired 'exception' handler.
    But how to handle the successProperty or invalid JSON data?

    No response at all

    - domi

  4. #4
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710

    Default

    Well, if there is no HTTP error, then the way the readRecords is currently written for Ext.data.Store, it appears that you need to return the a root object that has the same name as the configured proxy's 'root' property, otherwise it fails in that method and never comes back. IMO, this is a bug as the method should check the successProperty before looking for the root node, otherwise you are forced to return the root node even in error scenarios.

    You can check the success property of the returned data if the load event of the store is successfully fired by doing something like this:
    Code:
                                load: function (store, recs, success) {
                                    // Get data object that holds returned JSON
                                    var jsonResult = store.proxy.reader.jsonData;
    
                                    // Check for errors and display if needed
                                    if (!jsonResult.success) {
    But if there is an error in the readRecords in the Touch library...it doesn't appear to fire the 'exception' event if listened to on the proxy, reader, OR store.

  5. #5
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    48

    Default

    thank you!

    this seems to be a serious bug...
    but how do you handle a malformed JSON response?

    I'm still looking for a "how to handle exceptions in Sencha Touch" document... IMHO it's a pain in the ass w/ Sencha Touch!

    - domi

  6. #6
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710

    Default

    I totally agree with you, and the Touch forum is not well monitored by Sencha staff, so probably going to have to open a ticket to get answer. I see that you are a Premium Member so you should be able to do that right?

    Just make sure you post back here when you get an answer

  7. #7
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    48

    Default

    just want to let you know:

    I've still some problems with the exception handling, but I haven't opened a ticket so far.
    I'll get to this part later and if I've no solution at this time, I'll open a ticket.

    Of course, I keep you posted

    btw.: it's really quiet here and in the premium support forum too. there are others, looking for the sencha team...

    - domi

  8. #8
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    48

    Default

    (bump)

  9. #9
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    48

    Default

    And here's the answer:

    Code:
    Ext.override(Ext.data.JsonReader, {
        getResponseData: function(response) {
            try {
                var data = Ext.decode(response.responseText);
            }
            catch (ex) {
                //throw 'Ext.data.JsonReader.getResponseData: Unable to parse JSON returned by Server.';
                Ext.Msg.alert('Error', 'damn it');
            }
     
            if (!data) {
                //throw 'Ext.data.JsonReader.getResponseData: JSON object not found';
                Ext.Msg.alert('Error', 'damn it');
            }
     
            return data;
        }
    });
    - domi

  10. #10
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710

    Default

    Nice, so what event are you listening to for trapping malformed JSON errors, the exception event of the store?

Page 1 of 2 12 LastLast

Similar Threads

  1. [FIXED-334] Proxy Event 'exception' Never Firing
    By Shane F in forum Sencha Touch 1.x: Bugs
    Replies: 5
    Last Post: 28 Sep 2010, 6:22 PM
  2. Change Store Proxy URL without Creating New Store
    By rkdeiss in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 13 Apr 2010, 11:16 AM
  3. Store proxy exception fired though successful
    By augustinas in forum Ext 3.x: Help & Discussion
    Replies: 8
    Last Post: 7 May 2009, 3:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •