Graceful handling of cross-domain tilesource failures on IE<10

The TileSource error handling path used to raise non-obvious
"Unspecified error" exceptions on IE < 10 when configured with a URL
from a different origin (hostname or port) because the handler included
``xhr.status`` in the error message, triggering a security exception.

Now the second exception is caught and the log message will use the
original exception message instead to make the root cause more obvious.
This commit is contained in:
Chris Adams 2013-08-29 16:15:52 -04:00
parent 1b6cf93474
commit baa3559df1

View File

@ -320,9 +320,29 @@ $.TileSource.prototype = {
$.makeAjaxRequest( url, function( xhr ) {
var data = processResponse( xhr );
callback( data );
}, function ( xhr ) {
}, function ( xhr, exc ) {
var msg;
/*
IE < 10 will block XHR requests to different origins. Any property access on the request
object will raise an exception which we'll attempt to handle by formatting the original
exception rather than the second one raised when we try to access xhr.status
*/
try {
msg = "HTTP " + xhr.status + " attempting to load TileSource";
} catch ( e ) {
var formattedExc;
if ( typeof( exc ) == "undefined" || !exc.toString ) {
formattedExc = "Unknown error";
} else {
formattedExc = exc.toString();
}
msg = formattedExc + " attempting to load TileSource";
}
_this.raiseEvent( 'open-failed', {
message: "HTTP " + xhr.status + " attempting to load TileSource",
message: msg,
source: url
});
});