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."}
})