PDA

View Full Version : How to reject record on Ext.direct server exception



HriBB
24 Dec 2012, 12:10 PM
When you save a record with Ext.direct proxy and a server exception occurs, how can I reject the record? Callback function is not called, and there is no exception function on Ext.data.Operation.

I did find an ugly workaround, but there's gotta be a better way to do this ... or not???



// record with a fully working Ext.direct proxy
var record;

// create exception handler
var exceptionFn = Ext.bind(function(record) {
// reject record
record.reject();
// remove listener if exception occured
Ext.direct.Manager.un('exception', exceptionFn);
}, this, [record]);

// listen to Ext.direct exceptions
Ext.direct.Manager.on('exception', exceptionFn);

// save record
record.save({
callback: function(records, operation) {
// this never gets called if server exception occurs
// remove listener if exception did not occur
Ext.direct.Manager.un('exception', exceptionFn);
}
});

mitchellsimoens
26 Dec 2012, 8:47 AM
Couple issues I see. Using Ext.direct means you may have multiple requests bundled into a single request so if one fails then the others fail but that doesn't mean the record saving wasn't successful.

You shouldn't allow the direct router to fire anything that wouldn't give a successful JSON reading meaning if there was a server side error (like a PHP error). Each request needs to have success true/false to tell each request is successful or not.