1. #1
    Ext JS Premium Member cdomigan's Avatar
    Join Date
    Mar 2007
    Posts
    148
    Vote Rating
    1
    cdomigan is on a distinguished road

      0  

    Default Answered: metachange exception handling

    Answered: metachange exception handling


    I can't seem to see errors thrown within a metachange listener.

    Code:
    metachange: function(store, meta) {		
    	throw "META ERROR"; // No error thrown! Execution just stops.
    }
    Other async events ('load', etc) are throwing errors just fine in their listeners.
    -->

  2. Ah! Now I understand what you mean. Then one of the solutions to escape the try/catch block is to override the getResponseData().
    Code:
    Ext.define('Override.data.reader.Json', {
        override: 'Ext.data.reader.Json',
        getResponseData: function(response) {
            var data, error;
     
            try {
                data = Ext.decode(response.responseText);
                //return this.readRecords(data);
            } catch (ex) {
                error = new Ext.data.ResultSet({
                    total  : 0,
                    count  : 0,
                    records: [],
                    success: false,
                    message: ex.message
                });
                this.fireEvent('exception', this, response, error);
                Ext.Logger.warn('Unable to parse the JSON returned by the server');
                return error;
            }
            return this.readRecords(data);
        }
    }

  3. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    First, you should make sure 'metachange' event is fired on your store. This event is fired when the returned data from server includes metaData property.
    -->

  4. #3
    Ext JS Premium Member cdomigan's Avatar
    Join Date
    Mar 2007
    Posts
    148
    Vote Rating
    1
    cdomigan is on a distinguished road

      0  

    Default


    It appears the root of the issue is that onMetaChange() is fired by readRecords() in the context of a try/catch block inside getResponseData() in Ext.data.reader.Json.

    This catches the error and fires the "exception" event of the Reader, formatted with the assumption that it will only be handling an Ext.decode() (ie JSON parsing) error. This is clearly incorrect as there could also be any amount of erroneous code inside the metachange handler that will throw an error here.

    Anyone have any ideas how to resolve this? See getResponseData() in Ext.data.reader.Json for the offending code.
    -->

  5. #4
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    From the source code, the 'metachange' event is only fired if the returned data from server is in the right format and if it contains metaData property. If one of this condition is not satisfied, the event will not be fired. So, if because of any reason that the returned data is not in the right format that causes error when parsing it, the 'metachange' event will not be fired. Instead the 'exception' event will be fired.
    -->

  6. #5
    Ext JS Premium Member cdomigan's Avatar
    Join Date
    Mar 2007
    Posts
    148
    Vote Rating
    1
    cdomigan is on a distinguished road

      0  

    Default


    The "metachange" event is firing correctly. The problem is that errors originating from within "metachange" listeners are being swallowed by the try/catch block in getResponseData().
    -->

  7. #6
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    Ah! Now I understand what you mean. Then one of the solutions to escape the try/catch block is to override the getResponseData().
    Code:
    Ext.define('Override.data.reader.Json', {
        override: 'Ext.data.reader.Json',
        getResponseData: function(response) {
            var data, error;
     
            try {
                data = Ext.decode(response.responseText);
                //return this.readRecords(data);
            } catch (ex) {
                error = new Ext.data.ResultSet({
                    total  : 0,
                    count  : 0,
                    records: [],
                    success: false,
                    message: ex.message
                });
                this.fireEvent('exception', this, response, error);
                Ext.Logger.warn('Unable to parse the JSON returned by the server');
                return error;
            }
            return this.readRecords(data);
        }
    }
    -->

  8. #7
    Ext JS Premium Member cdomigan's Avatar
    Join Date
    Mar 2007
    Posts
    148
    Vote Rating
    1
    cdomigan is on a distinguished road

      0  

    Talking


    Works a treat! Thanks!
    -->

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi