Results 1 to 7 of 7

Thread: AJAX Exception Handling

  1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
      0  

    Default AJAX Exception Handling

    I've tried several approaches to trap ajax successes and failures, but I can't seem to get it working. What is the correct approach to use to trap 500 errors and json data format errors? I'm not sure it matters, but I'm using Ext.define and not Ext.create and I'm using PR3.

    Thanks,

    Bruce


    Code:
    Ext.define('MyModel', {
        extend: 'Ext.data.Model',
    
        fields: [
            {name: "field", type: "string"},
        ],
    
        proxy: {
            type: 'ajax',
            url: "users.json",
            reader: 'json',
    
            listeners: {
                exception: {
                    success: function() {
                        console.log("MyModel success.");
                    },
                    failure: function() {
                        console.log("MyModel failure.");
                    }
                },
                success: function(response) {
                    console.log("MyModel: success", response);
                },
                failure: function(response) {
                    console.log("MyModel: failure", response);
                }
            },
            exception: function(resp, oper, opts) {
               console.log("MyModel: exception", resp, oper, opts);
            },
            success: function(response) {
                console.log("MyModel: success", response);
            },
            failure: function(response) {
                console.log("MyModel: failure", response);
            }
        }

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    How are you loading the data? From a Store or from Model.load?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
      0  

    Default

    I'm loading the data from the store using autoLoad: true.

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    Quote Originally Posted by bweiler View Post
    I'm loading the data from the store using autoLoad: true.
    Ok... so listen for the exception event on the store.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
      0  

    Default Still no luck

    I tried the following and it still doesn't work. If the code is correct below, then I'll try to come up with a working example that shows the problem.

    Thanks,

    Bruce

    Code:
    Ext.define('MyData', {
        extend: 'Ext.data.Store',
        model: 'MyModel',
        autoLoad: true,
        exception: function(resp, oper, opts) {
               console.log("MyModel: exception", resp, oper, opts);
        },    
    }
    

  6. #6
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    Quote Originally Posted by bweiler View Post
    I tried the following and it still doesn't work. If the code is correct below, then I'll try to come up with a working example that shows the problem.

    Thanks,

    Bruce

    Code:
    Ext.define('MyData', {
        extend: 'Ext.data.Store',
        model: 'MyModel',
        autoLoad: true,
        exception: function(resp, oper, opts) {
               console.log("MyModel: exception", resp, oper, opts);
        },    
    }
    
    Of course that won't work. You created a new method, not listener...

    Code:
    Ext.define('MyData', {
        extend : 'Ext.data.Store',
    
        model : 'MyModel',
        autoLoad : true,
    
        constructor: function(config) {
            this.callParent(arguments);
    
            this.on('exception', someFn, this);
        }
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  7. #7
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
      0  

    Default

    I'm very excited about Sencha Touch 2.0. The MVC approach is much cleaner and easy to understand and I am able to implement application features twice as fast as with 1.x. I hope the ajax exception handling will also be improved by the time 2.0 releases.

    I'm not sure if the Ext.data.StoreManager listeners configuration option is an artifact or an unimplemented feature, but it would be nice if it worked.

    In the meantime, I can see from your code how to set a listener on the store from within the MVC controller using the Ext.data.StoreManager.get() method if I don't use autoLoad. Otherwise, it looks like I will need to use the internal approach you described above when using the autoLoad option in the stores.

    Thanks again for your help,

    Bruce

Posting Permissions

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