PDA

View Full Version : [OPEN-1127] Uncatchable Exception after file upload returns invalid response



SimonSez07
14 Jul 2010, 9:30 PM
If an HTTP or server-side error occurs when submitting a file upload (async IFRAME upload) then the exception surfaces to the browser and cannot be handled as far as I can tell.

The error happens because the responseText of the iframe is not valid JSON and the exception is thrown at line 66304 (Ext v3.2.1, debug file w/ comments).

I don't know if this is a known bug or if there are plans to make Ext more resilient, but I have managed to fix it by changing a few lines.

Rather than editing Ext source, here is an override workaround:


Ext.override(Ext.form.Action.Submit, {
success : function(response){
var result = this.processResponse(response);
if(result === true || result.success){
this.form.afterAction(this, true);
return;
}
if(result.errors){
this.form.markInvalid(result.errors);
}
if (!this.failureType) this.failureType = Ext.form.Action.SERVER_INVALID;
this.form.afterAction(this, false);
},
handleResponse : function(response){
if(this.form.errorReader){
var rs = this.form.errorReader.read(response);
var errors = [];
if(rs.records){
for(var i = 0, len = rs.records.length; i < len; i++) {
var r = rs.records[i];
errors[i] = r.data;
}
}
if(errors.length < 1){
errors = null;
}
return {
success : rs.success,
errors : errors
};
}
try {
return Ext.decode(response.responseText);
} catch(e) {
this.failureType = Ext.form.Action.LOAD_FAILURE;
return false;
}
}
});


The modified lines are the one begining with if (!this.failureType) and the try/catch block. I hope this can be useful to someone else.

- Simon