PDA

View Full Version : Exception handling in store



Misiu
10 Apr 2014, 5:35 AM
In my application I'm handling bad responses for rest requests like so:


//try to delete item
s.eventStore.remove(s.ctx.rec);
//error handling
s.eventStore.getProxy().on({
exception: function() {
s.eventStore.rejectChanges();
Ext.MessageBox.show({
title: 'Server error',
msg: 'data restored',
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}});

This works fine, but I would like to move exception handling to store. I tried modifying my store like so:


Ext.define('Urlopy.Store.Holidays', {
extend: "Sch.data.EventStore",
autoLoad: false,
autoSync: true,
batch: false,
proxy: {
type: 'rest',
pageParam: false, //to remove param "page"
startParam: false, //to remove param "start"
limitParam: false, //to remove param "limit"
noCache: false, //to remove param "_dc"
url: window.appUrl + 'api/Holidays',
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json'
},
listeners: {
exception: function(proxy, response, operation) {
console.log("proxy");
console.log(proxy);
console.log("response");
console.log(response);
console.log("operation");
console.log(operation);


this.rejectChanges();
},
scope: this
}
},
model: 'Urlopy.Model.Holiday'
});

but I get error saying:

Uncaught TypeError: Object [object global] has no method 'rejectChanges'

My problem is getting reference to store inside exception, so I'll be able to call rejectChanges.
How should I modify my store to get this working?

Zinnia
14 Apr 2014, 1:19 AM
Check the below thread hope this may solve your issue.
http://www.sencha.com/forum/showthread.php?147882-Get-store-from-proxy

Misiu
14 Apr 2014, 5:55 AM
Check the below thread hope this may solve your issue.
http://www.sencha.com/forum/showthread.php?147882-Get-store-from-proxy
Thanks for this link! I was searching for solution on forum, but I couldn't find one. I must look harder next time :)