PDA

View Full Version : [DUPE-1413] DataProxy Exception - JsonReader - Possible Inconsistency



zachext
11 Feb 2010, 2:19 PM
Ext version tested:

Ext 3.1.1


Adapter used:

ext




Description:

In the readResponse method of a JsonReader, if a “create” action is being processed, a JsonReader error can be thrown before the success property is checked. If no records are present, this behavior results in a “response” exception back at the DataProxy. If the create action on the server fails, there will be no IDs to send back, however, it is still possible to send back a valid response.
Put another way, if a create action fails due to a database constraint, (depending on the configuration of the JsonReader) you always end up with a raw response object rather than the decoded object.
In order to get the “remote” exception, it is necessary to place an empty object in the records array.





If the response has nothing in the records array:


{"records":[],"success":false,"message":"The record could not be created."}


The exception type is "response" and message is undefined


Ext.data.DataProxy.addListener('exception', function() {
//raw response Object -message is undefined
Ext.Msg.alert('Error', arguments[4].message);

});




If the response has an empty object in the records array


{"records":[{}],"success":false,"message":"The record could not be created."}


The exception is the expected "remote" type and the decoded response is available.


Ext.data.DataProxy.addListener('exception', function() {
Ext.Msg.alert('Error', arguments[4].message);
});











Here is the relevant method from JsonReader:


readResponse : function(action, response) {
var o = (response.responseText !== undefined) ? Ext.decode(response.responseText) : response;
if(!o) {
throw new Ext.data.JsonReader.Error('response');
}

var root = this.getRoot(o);
if (action === Ext.data.Api.actions.create) {
var def = Ext.isDefined(root);
if (def && Ext.isEmpty(root)) {
throw new Ext.data.JsonReader.Error('root-empty', this.meta.root);
}
else if (!def) {
throw new Ext.data.JsonReader.Error('root-undefined-response', this.meta.root);
}
}

// instantiate response object
var res = new Ext.data.Response({
action: action,
success: this.getSuccess(o),
data: (root) ? this.extractData(root, false) : [],
message: this.getMessage(o),
raw: o
});

// blow up if no successProperty
if (Ext.isEmpty(res.success)) {
throw new Ext.data.JsonReader.Error('successProperty-response', this.meta.successProperty);
}
return res;
},





And here is the relevant point where the exception event is thrown from HttpProxy:



onWrite : function(action, o, response, rs) {
var reader = o.reader;
var res;
try {
res = reader.readResponse(action, response);
} catch (e) {
this.fireEvent('exception', this, 'response', action, o, response, e);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
if (res.success === true) {
this.fireEvent('write', this, action, res.data, res, rs, o.request.arg);
} else {
this.fireEvent('exception', this, 'remote', action, o, res, rs);
}

o.request.callback.call(o.request.scope, res.data, res, res.success);
},

sumit.madan
7 Oct 2010, 1:33 PM
Another 3 hours wasted due to this issue. Why is this bug hanging around since Feb? Still present in 3.2.2

zachext
7 Dec 2010, 9:35 AM
Looks like this has a fix [1413] : http://www.sencha.com/forum/showthread.php?117126