From: Alexander Ebert Date: Thu, 20 Oct 2011 15:36:47 +0000 (+0200) Subject: Fixed AJAX-response exceptions X-Git-Tag: 2.0.0_Beta_1~1673 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=03812bbc39e37d4549ed8029b44ecabe7098f14c;p=GitHub%2FWoltLab%2FWCF.git Fixed AJAX-response exceptions Providing a stacktrace for debugging purpose (will be removed later or at least toggled by some kind of debug switch) and fixed styling (was completely unreadable and messed up). --- diff --git a/wcfsetup/install/files/acp/style/style.css b/wcfsetup/install/files/acp/style/style.css index 33c3684f56..80d9a2714a 100644 --- a/wcfsetup/install/files/acp/style/style.css +++ b/wcfsetup/install/files/acp/style/style.css @@ -3173,5 +3173,28 @@ div#profileButtonContainer button:hover { +/* DEBUG ONLY - DO NOT TOUCH! */ + +.ui-dialog-title { + font-weight: bold !important; + text-shadow: 1px 0px 0px rgb(0, 0, 0) !important; +} + +div.ajaxDebugMessage p { + border-bottom: 1px solid rgb(192, 192, 192); + margin: 0 3px; + padding: 7px 0 3px 0; +} + +div.ajaxDebugMessage p:first-child, +div.ajaxDebugMessage p:last-child { + border-bottom-width: 0; + margin: 0; + padding: 3px; +} + +div.ajaxDebugMessage p:last-child { + font-family: Monospace; +} /* -- -- -- -- -- EOF -- -- -- -- -- */ diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 6f443d1f21..2dd547084f 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -997,12 +997,12 @@ WCF.Action.Proxy.prototype = { } var $randomID = WCF.getRandomID(); - $('

Der Server antwortete: ' + data.message + '.

').wcfDialog(); + $('

Der Server antwortete: ' + data.message + '

Stacktrace:

' + data.stacktrace + '

').wcfDialog(); } // failed to parse JSON catch (e) { var $randomID = WCF.getRandomID(); - $('

Der Server antwortete: ' + jqXHR.responseText + '.

').wcfDialog(); + $('

Der Server antwortete: ' + jqXHR.responseText + '.

').wcfDialog(); } this._after(); @@ -2470,6 +2470,8 @@ WCF.Collapsible.Remote = Class.extend({ var $isOpen = this._containers[containerID].data('isOpen'); var $button = $('').prependTo(buttonContainer); $button.data('containerID', containerID).click($.proxy(this._toggleContainer, this)); + + return $button; }, /** @@ -2506,6 +2508,18 @@ WCF.Collapsible.Remote = Class.extend({ } }); this._proxy.sendRequest(); + + // set spinner for current button + this._showSpinner($button); + }, + + _showSpinner: function(button) { + console.debug('Updating icon'); + button.attr('src', WCF.Icon.get('wcf.icon.loading')); + }, + + _hideSpinner: function(button, newIcon) { + button.attr('src', newIcon); }, /** @@ -2538,6 +2552,8 @@ WCF.Collapsible.Remote = Class.extend({ // update container content this._containerData[$containerID].target.html(data.returnValues.content); + + } }); diff --git a/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php b/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php index cc357b44af..a446e5995e 100644 --- a/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php @@ -1,6 +1,7 @@ getMessage()); + throw new AJAXException($e); } } } @@ -99,10 +100,10 @@ class AJAXProxyAction extends AbstractSecureAction { // validate class name if (!class_exists($this->className)) { - throw new AJAXException("unknown class '".$this->className."'"); + throw new SystemException("unknown class '".$this->className."'"); } if (!ClassUtil::isInstanceOf($this->className, 'wcf\data\IDatabaseObjectAction')) { - throw new AJAXException("'".$this->className."' should implement wcf\system\IDatabaseObjectAction"); + throw new SystemException("'".$this->className."' should implement wcf\system\IDatabaseObjectAction"); } // create object action instance @@ -113,7 +114,7 @@ class AJAXProxyAction extends AbstractSecureAction { $this->objectAction->validateAction(); } catch (ValidateActionException $e) { - throw new AJAXException("validation failed: ".$e->getMessage()); + throw new SystemException("validation failed: ".$e->getMessage()); } // execute action @@ -121,7 +122,7 @@ class AJAXProxyAction extends AbstractSecureAction { $this->response = $this->objectAction->executeAction(); } catch (\Exception $e) { - throw new AJAXException('unknown exception caught: '.$e->getMessage()); + throw new SystemException('unknown exception caught: '.$e->getMessage()); } $this->executed(); diff --git a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php index df5d2fd080..dec8b4a0f9 100644 --- a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php +++ b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php @@ -16,14 +16,20 @@ class AJAXException extends \Exception { /** * Throws a JSON-encoded error message * - * @param string $message + * @param \Exception $exception */ - public function __construct($message) { + public function __construct(\Exception $exception) { + $stacktrace = $exception->getTraceAsString(); + if ($exception instanceof SystemException) { + $stacktrace = $exception->__getTraceAsString(); + } + //header('HTTP/1.0 418 I\'m a Teapot'); header('HTTP/1.0 503 Service Unavailable'); header('Content-type: application/json'); echo JSON::encode(array( - 'message' => $message + 'message' => $exception->getMessage(), + 'stacktrace' => nl2br($stacktrace) )); exit; }