From baa3559df187b74fdd54caff87eddef2d8bb132b Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Thu, 29 Aug 2013 16:15:52 -0400 Subject: [PATCH] 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. --- src/tilesource.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/tilesource.js b/src/tilesource.js index fb22b21c..e1529b3f 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -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 }); });