1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    82
    Answers
    5
    Vote Rating
    1
    markevans is on a distinguished road

      0  

    Default Unanswered: Jsonp retry if error on Store load - how best to implement?

    Unanswered: Jsonp retry if error on Store load - how best to implement?


    Implementing the Navigation View with Lists populated by a JsonP call was a piece of cake, and one of the easiest parts of the project I'm working on. However, turns out the API provider (Edmunds.com) frequently returns an error, so I need to build something to check for the error and retry.

    I can't seem to find any event that would allow me to evaluate the data before the load to the Store actually happens, and the API response doesn't conform to the Reader Events (there's no "success" property). If I rip it up enough from its initially awesomely compact form, I'm sure I can find a way but if anyone knows a reasonably elegant way to address, I'd greatly appreciate.

    My code for the Store:
    Code:
    Ext.define('Rebate.store.Models', {
        extend: 'Ext.data.Store',
    
    
        config: {
            model: 'Rebate.model.Model',
            autoLoad: false,
            storeId: 'modelStore',
            sorters: 'name',
            
            listeners: {
                        beforeload: function(store){
                            store.setProxy({
                                type: 'jsonp',
                                url: 'http://api.edmunds.com/v1/api/vehicle/modelrepository/findnewmodelsbymakeid?makeId=' + Rebate.util.Config.getNewmakeid() + '&api_key=xxxxxxxxxxxxxxxx&fmt=json',
    
    
                                reader: {
                                    type: 'json',
                                    rootProperty: 'modelHolder'
                                    }
                                }
                                });
                            }
                    }
    }
    });
    API Response when it fails:
    Code:
    Ext.data.JsonP.callback2({
     "error": {"code":504, "message":"Response took longer than expected. Gateway Timed out."}
    })

  2. #2
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Answers
    21
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default


    You can listen for errors on the JsonP proxy

    http://docs.sencha.com/touch/2-0/#!/...vent-exception

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    82
    Answers
    5
    Vote Rating
    1
    markevans is on a distinguished road

      0  

    Default


    I tried adding the a listener for the exception event. This error doesn't trigger it.

Thread Participants: 1

Tags for this Thread