I have an http API which (shockingly new technique) reacts on different errors setting different response statuses.
The question is - while using Ext.data.Store with some XMLHttpRequest-inside proxy, what is the best way to handle this statuses? As far as I can understand, "load" event does not pass status directly, as well as "exception", and the last one actually doesn't even trigger when 4** status is received.
So, as I can see from code xhr instance is hidden from Ext.data.store, so the question is also can be stated as "What is best extjs practice to handle low-level xhr object".
There is no exception event on Ext.data.Store. Instead, it is Ext.data.proxy.Server and its sub-classes (like Ext.data.proxy.Ajax) that define an exception event. Listeners receive a response object which includes the http status.
Depending on your setup, you can register a listener on the store's proxy, or - if your store uses a model - on the model's proxy.
This test setup worked for me on Chrome 14 and FF 6:
var store = Ext.create('Ext.data.Store', {
fields: [ 'field1', 'field2'],
proxy: {
type: 'ajax',
url: 'api/data.json',
reader: {
type: 'json',
root: 'data'
},
listeners: {
exception: function(proxy, exception, operation) {
console.log(response.status);
}
}
},
});
store.load();
The exception event does provide a response
object which has a status
property containing the HTML status code you want to see.
If your exception is indeed not fired by 4** errors (which in my experience do fire) you could try to register an ajax listener instead:
Ext.Ajax.on('requestexception', exceptionHandlerMethod);
and
function exceptionHandlerMethod(connection, response, requestOptions, listenerOptions) {
if(response.status == 401) {
alert('401 error');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With