PDA

View Full Version : Ext.Loader how to handle loading errors ?



armandoxxx
15 Oct 2012, 1:16 AM
Hey guys

How to I handle Ext.Loader errors?

Example:

User session expires on server. And user is trying to open a window component which triggers Ext.Loader to load that component from server. Since back-end does not allow files to be loaded unless you're logged in my question is how to handle 401 http status (unauthorized).

KInd regards

Armando

armandoxxx
15 Oct 2012, 3:33 AM
Allthough I hate overriding default ext functionality, I found out that ext-all-debug.js script #5834 has an empty else statement which should include at least some kind of error hook or something so this loading problems can be handled.

My current fix is ...


Ext.override(Ext.Loader,{

loadScriptFile: function(url, onLoad, onError, scope, synchronous) {

if (this.isFileLoaded[url]) {
return Loader;
}

var config = Ext.Loader.getConfig(),
noCacheUrl = url + (config.disableCaching ? ('?' + config.disableCachingParam + '=' + Ext.Date.now()) : ''),
isCrossOriginRestricted = false,
xhr, status, onScriptError,
debugSourceURL = "";

scope = scope || Loader;

Ext.Loader.isLoading = true;

if (!synchronous) {
onScriptError = function() {
};

this.scriptElements[url] = Ext.Loader.injectScriptElement(noCacheUrl, onLoad, onScriptError, scope);
} else {
if (typeof XMLHttpRequest != 'undefined') {
xhr = new XMLHttpRequest();
} else {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}

try {
xhr.open('GET', noCacheUrl, false);
xhr.send(null);
} catch (e) {
isCrossOriginRestricted = true;
}

status = (xhr.status === 1223) ? 204 :
(xhr.status === 0 && (self.location || {}).protocol == 'file:') ? 200 : xhr.status;

isCrossOriginRestricted = isCrossOriginRestricted || (status === 0);

if (isCrossOriginRestricted
) {
}
else if ((status >= 200 && status < 300) || (status === 304)
) {


if (!Ext.isIE) {
debugSourceURL = "\n//@ sourceURL=" + url;
}

Ext.globalEval(xhr.responseText + debugSourceURL);

onLoad.call(scope);
}
else {

/**
THIS IS EMPTY ELSE !!!

PUT YOUR ERROR HANDLING CODE HERE !!!
**/

}
xhr = null;
}
}

});



Regards

Armando