Tuesday, October 9, 2012

Global exception handling for data requests

In 3.3x there was the option to register 'global' exception handling by adding a listener to the DataProxy:
Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
    if (type === 'remote') {
        Ext.Msg.show({
            title: 'REMOTE EXCEPTION',
            msg: res.message,
            icon: Ext.MessageBox.ERROR,
            buttons: Ext.Msg.OK
        });
    }
});  

In EXTJs 4 we can implement it like this:
Ext.override(Ext.data.proxy.Server, {

        constructor: function(config)
        {
            this.callOverridden([config]);

            this.addListener("exception",  function (proxy,
            response, operation) {
                if (response.responseText != null)
                {
                    Ext.Msg.alert('Error', response.responseText);
                }
            });

        }

});
  

No comments:

Post a Comment