Fixed AJAX-response exceptions
authorAlexander Ebert <ebert@woltlab.com>
Thu, 20 Oct 2011 15:36:47 +0000 (17:36 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 20 Oct 2011 15:36:47 +0000 (17:36 +0200)
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).

wcfsetup/install/files/acp/style/style.css
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/action/AJAXProxyAction.class.php
wcfsetup/install/files/lib/system/exception/AJAXException.class.php

index 33c3684f568c6f6786a5a63d252aac4995800ec0..80d9a2714a6263bf9283d094d0f04e15da573c41 100644 (file)
@@ -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 -- -- -- -- -- */
index 6f443d1f21d854c575efa614ebb7859075cb8b9f..2dd547084f1fa9cac7be20ad33bb50402af8280b 100644 (file)
@@ -997,12 +997,12 @@ WCF.Action.Proxy.prototype = {
                        }
                        
                        var $randomID = WCF.getRandomID();
-                       $('<div id="' + $randomID + '" title="HTTP/1.0 ' + jqXHR.status + ' ' + errorThrown + '"><p>Der Server antwortete: ' + data.message + '.</p></div>').wcfDialog();
+                       $('<div class="ajaxDebugMessage" id="' + $randomID + '" title="HTTP/1.0 ' + jqXHR.status + ' ' + errorThrown + '"><p>Der Server antwortete: ' + data.message + '</p><p>Stacktrace:</p><p>' + data.stacktrace + '</p></div>').wcfDialog();
                }
                // failed to parse JSON
                catch (e) {
                        var $randomID = WCF.getRandomID();
-                       $('<div id="' + $randomID + '" title="HTTP/1.0 ' + jqXHR.status + ' ' + errorThrown + '"><p>Der Server antwortete: ' + jqXHR.responseText + '.</p></div>').wcfDialog();
+                       $('<div class="ajaxDebugMessage" id="' + $randomID + '" title="HTTP/1.0 ' + jqXHR.status + ' ' + errorThrown + '"><p style="padding: 3px;">Der Server antwortete: ' + jqXHR.responseText + '.</p></div>').wcfDialog();
                }
                
                this._after();
@@ -2470,6 +2470,8 @@ WCF.Collapsible.Remote = Class.extend({
                var $isOpen = this._containers[containerID].data('isOpen');
                var $button = $('<img src="' + WCF.Icon.get('wcf.icon.' + ($isOpen ? 'closed' : 'opened')) + '" alt="" />').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);
+
+
        }
 });
 
index cc357b44af0ac609ff2876142c2ab76959afee26..a446e5995e039aefa80da1a71723f5563702a799 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\action;
 use wcf\system\exception\AJAXException;
+use wcf\system\exception\SystemException;
 use wcf\system\exception\ValidateActionException;
 use wcf\util\ArrayUtil;
 use wcf\util\ClassUtil;
@@ -66,7 +67,7 @@ class AJAXProxyAction extends AbstractSecureAction {
                                throw $e;
                        }
                        else {
-                               throw new AJAXException($e->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();
                
index df5d2fd080ee962f4dba373c5a83065229b5dfc8..dec8b4a0f90d2028631afd09c909927168a721a2 100644 (file)
@@ -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;
        }