PDA

View Full Version : [OPEN-1281] No exception event launched for DirectProxy read with success:false



fdeslandes
15 Sep 2010, 12:13 PM
Ext version tested:


Ext 3.2 rev 2



Adapter used:


ext



Browser versions tested against:


FF3 (firebug 1.3.0.10 installed)



Operating System:


Win 7



Description:


When sending back json from the server with success:false to a read action of a DirectProxy used with a grid, the exception event is not launched.



Debugging already done:


Found the problem in onRead method of DirectProxy :


onRead : function(action, trans, result, res) {
var records;
try {
records = trans.reader.readRecords(result);
}
catch (ex) {
this.fireEvent("loadexception", this, trans, res, ex);

this.fireEvent('exception', this, 'response', action, trans, res, ex);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}
this.fireEvent("load", this, res, trans.request.arg);
trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
}
readRecord Code from the JSON Writer is:


readRecords : function(o){
this.jsonData = o;
if(o.metaData){
this.onMetaChange(o.metaData);
}
var s = this.meta, Record = this.recordType,
f = Record.prototype.fields, fi = f.items, fl = f.length, v;

var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
if(s.totalProperty){
v = parseInt(this.getTotal(o), 10);
if(!isNaN(v)){
totalRecords = v;
}
}
if(s.successProperty){
v = this.getSuccess(o);
if(v === false || v === 'false'){
success = false;
}
}

return {
success : success,
records : this.extractData(root, true),
totalRecords : totalRecords
};
}
As we can see, it doesn't throw an exception when success is false, instead returning it in the result.

The onWrite method, however, manages exceptions correctly:


onWrite : function(action, trans, result, res, rs) {
var data = trans.reader.extractData(trans.reader.getRoot(result), false);
var success = trans.reader.getSuccess(result);
success = (success !== false);
if (success){
this.fireEvent("write", this, action, data, res, rs, trans.request.arg);
}else{
this.fireEvent('exception', this, 'remote', action, trans, result, rs);
}
trans.request.callback.call(trans.request.scope, data, res, success);
}Something similar should be done for onRead.

If it's not a bug and is intended, would you care to explain why the success property have no effect on DirectStores' read actions and also tell me if there is a standard way of managing success:false returns when loading the store ?

Thanks.

Jamie Avins
20 Sep 2010, 9:44 AM
This does look like an oversight and should be in place for the onRead method as well.

fdeslandes
20 Sep 2010, 9:57 AM
Thanks.

Here is my temporary fix:


// Add support for success property in DirectProxy read calls
Ext.override(Ext.data.DirectProxy,
{
onRead : function(action, trans, result, res)
{
var records;
try
{
records = trans.reader.readRecords(result);
}
catch (ex)
{
this.fireEvent("loadexception", this, trans, res, ex);

this.fireEvent('exception', this, 'response', action, trans, res, ex);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}

if(trans.reader.getSuccess(result) === false)
{
this.fireEvent("loadexception", this, trans, res);

this.fireEvent('exception', this, 'remote', action, trans, res.result);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}

this.fireEvent("load", this, res, trans.request.arg);
trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
}
});