PDA

View Full Version : Error handling with store



toxkillfraex
25 Apr 2012, 4:22 AM
I'm looking for a way to handle server thrown errors 400 404 blah blah you know the drill

but so far I haven't found a good way to do this that actually WORKS...
I've seen crap with loadexception but I'm guessing this is for an older version so that's the deadest end I could've found.

there's if(success)
in load but then I get a message the framework itself generates whereas the actual server message (which I don't find in ANY of the load objects) is:
1) translated
2) exactly about what's being requested

any help is appreciated

scottmartin
25 Apr 2012, 10:05 AM
You can create a listener on your model:



Ext.define('myModel', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [..],
proxy: {
type: 'ajax',
actionMethods: 'POST',
api: {..},
reader: {..},
writer: {..},
listeners: {
exception: function(proxy, response, operation) {
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});


You could also add requestexception listener to Ext.data.Connection

Regards,
Scott.

toxkillfraex
26 Apr 2012, 12:56 AM
You can create a listener on your model:



Ext.define('myModel', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [..],
proxy: {
type: 'ajax',
actionMethods: 'POST',
api: {..},
reader: {..},
writer: {..},
listeners: {
exception: function(proxy, response, operation) {
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});


You could also add requestexception listener to Ext.data.Connection

Regards,
Scott.
worked like a charm to get me to the answer. I tried that listener on the store, on the reader but not the proxy xP

I just used the response (with decode) instead of operation to get me the original server message.

thanks for the help