2013년 10월 17일 목요일

Handling Store exceptions

1. Define the Model that we will attempt to load data into:
Ext.define('Book', {
extend: 'Ext.data.Model',
fields: [{
name: 'Title',
type: 'string'
}]
});

2. Add an AJAX Proxy to the Model, defining the url config option as
error-response.json:
Ext.define('Book', {
...
proxy: {
type: 'ajax',
url: 'error-response.json'
}
});

3. Listen for the exception event on the AJAX proxy. The exception event will be fired
should the server return an exception:
proxy: {
...
listeners: {
'exception': function(proxy, response, operation, eOpts){
}
}
}

4. Add logic to the function to change the behavior depending on the type of error.
'exception': function(proxy, response, operation, eOpts){
if (response.status !== 200) {
alert(response.status + ' ' + response.statusText);
} else {
var responseText = Ext.decode(response.responseText);
alert(responseText.error);
}
}

댓글 없음:

댓글 쓰기