Merge pull request #2142 from Aiosa/master

Delegate error printing to the ajax caller.
This commit is contained in:
Ian Gilman 2022-04-15 14:12:39 -07:00 committed by GitHub
commit 334e8fbc67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 7 deletions

View File

@ -122,6 +122,18 @@ $.EventSource.prototype = {
}
},
/**
* Get the amount of handlers registered for a given event.
* @param {String} eventName - Name of event to inspect.
* @return {number} amount of events
*/
numberOfHandlers: function (eventName) {
var events = this.events[ eventName ];
if ( !events ) {
return 0;
}
return events.length;
},
/**
* Remove all event handlers for a given event type. If no type is given all

View File

@ -130,7 +130,7 @@ ImageJob.prototype = {
self.image.src = url;
},
error: function(request) {
self.errorMsg = "Image load aborted - XHR error";
self.errorMsg = "Image load aborted - XHR error: Ajax returned " + request.status;
self.finish(false);
}
});

View File

@ -2364,10 +2364,10 @@ function OpenSeadragon( options ){
protocol !== "https:" )) {
onSuccess( request );
} else {
$.console.error( "AJAX request returned %d: %s", request.status, url );
if ( $.isFunction( onError ) ) {
onError( request );
} else {
$.console.error( "AJAX request returned %d: %s", request.status, url );
}
}
}

View File

@ -529,7 +529,7 @@ $.TileSource.prototype = {
exception rather than the second one raised when we try to access xhr.status
*/
try {
msg = "HTTP " + xhr.status + " attempting to load TileSource";
msg = "HTTP " + xhr.status + " attempting to load TileSource: " + url;
} catch ( e ) {
var formattedExc;
if ( typeof ( exc ) === "undefined" || !exc.toString ) {
@ -538,9 +538,11 @@ $.TileSource.prototype = {
formattedExc = exc.toString();
}
msg = formattedExc + " attempting to load TileSource";
msg = formattedExc + " attempting to load TileSource: " + url;
}
$.console.error(msg);
/***
* Raised when an error occurs loading a TileSource.
*

View File

@ -58,8 +58,8 @@
assert.equal($(".openseadragon-message").length, 1, "Open failures should display a message");
assert.ok(testLog.error.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'),
"AJAX failures should be logged to the console");
assert.ok(testLog.error.contains('["HTTP 404 attempting to load TileSource: /test/data/not-a-real-file"]'),
"'open-failed' fired after AJAX error handler prints error to the console.'");
done();
});

View File

@ -1152,6 +1152,36 @@
});
// ----------
QUnit.test( 'Viewer: event count test with \'tile-drawing\'', function (assert) {
var done = assert.async();
assert.ok(viewer.numberOfHandlers('tile-drawing') === 0,
"'tile-drawing' event is empty by default.");
var tileDrawing = function ( event ) {
viewer.removeHandler( 'tile-drawing', tileDrawing );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 0,
"'tile-drawing' deleted: count is 0.");
viewer.close();
done();
};
var tileDrawingDummy = function ( event ) {};
viewer.addHandler( 'tile-drawing', tileDrawing );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 1,
"'tile-drawing' event set to 1.");
viewer.addHandler( 'tile-drawing', tileDrawingDummy );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 2,
"'tile-drawing' event set to 2.");
viewer.removeHandler( 'tile-drawing', tileDrawingDummy );
assert.ok(viewer.numberOfHandlers('tile-drawing') === 1,
"'tile-drawing' deleted once: count is 1.");
viewer.open( '/test/data/testpattern.dzi' );
} );
QUnit.test( 'Viewer: tile-drawing event', function (assert) {
var done = assert.async();
var tileDrawing = function ( event ) {