From f4df2a3b2a9c37e31458e94cb09669ac17a70f11 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 21 Dec 2007 23:42:05 +0000 Subject: [PATCH] Changing prototype.js ajax stuff so exceptions aren't swallowed by default. If you want this behavior, set request.options.onException to something that swallows, or use OpenLayers.Ajax.Responders.register for onException. r=crschmidt (closes #1232) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5567 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Ajax.js | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Ajax.js b/lib/OpenLayers/Ajax.js index 28ff35c90e..df42d33544 100644 --- a/lib/OpenLayers/Ajax.js +++ b/lib/OpenLayers/Ajax.js @@ -493,14 +493,49 @@ OpenLayers.Ajax.Request = OpenLayers.Class(OpenLayers.Ajax.Base, { /** * Method: dispatchException + * If the optional onException function is set, execute it + * and then dispatch the call to any other listener registered + * for onException. + * + * If no optional onException function is set, we suspect that + * the user may have also not used + * OpenLayers.Ajax.Responders.register to register a listener + * for the onException call. To make sure that something + * gets done with this exception, only dispatch the call if there + * are listeners. + * + * If you explicitly want to swallow exceptions, set + * request.options.onException to an empty function (function(){}) + * or register an empty function with + * for onException. * * Parameters: * exception - {?} */ dispatchException: function(exception) { - (this.options.onException || - OpenLayers.Ajax.emptyFunction)(this, exception); - OpenLayers.Ajax.Responders.dispatch('onException', this, exception); + var handler = this.options.onException; + if(handler) { + // call options.onException and alert any other listeners + handler(this, exception); + OpenLayers.Ajax.Responders.dispatch('onException', this, exception); + } else { + // check if there are any other listeners + var listener = false; + var responders = OpenLayers.Ajax.Responders.responders; + for (var i = 0; i < responders.length; i++) { + if(responders[i].onException) { + listener = true; + break; + } + } + if(listener) { + // call all listeners + OpenLayers.Ajax.Responders.dispatch('onException', this, exception); + } else { + // let the exception through + throw exception; + } + } } });