1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    bweiler is on a distinguished road

      0  

    Default AJAX Exception Handling

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    How are you loading the data? From a Store or from Model.load?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    bweiler is on a distinguished road

      0  

    Default


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

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    bweiler is on a distinguished road

      0  

    Default Still no luck

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  7. #7
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    bweiler is on a distinguished road

      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

Thread Participants: 1