Fixed AJAX exception handling
authorAlexander Ebert <ebert@woltlab.com>
Fri, 18 Nov 2016 16:51:05 +0000 (17:51 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 18 Nov 2016 16:51:05 +0000 (17:51 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js
wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php
wcfsetup/install/files/lib/system/exception/AJAXException.class.php

index 50659b34ae5e614d80e9d0fa36b2f066e143d02d..6bab12a61899d3535400359722ec7fe545abe15d 100644 (file)
@@ -272,10 +272,15 @@ define(['Core', 'Language', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Dialog', 'Wolt
                                var message = '';
                                
                                if (data !== null) {
-                                       if (data.stacktrace) details = '<br /><p>Stacktrace:</p><p>' + data.stacktrace + '</p>';
-                                       else if (data.exceptionID) details = '<br /><p>Exception ID: <code>' + data.exceptionID + '</code></p>';
+                                       if (data.stacktrace) details = '<br><p>Stacktrace:</p><p>' + data.stacktrace + '</p>';
+                                       else if (data.exceptionID) details = '<br><p>Exception ID: <code>' + data.exceptionID + '</code></p>';
                                        
                                        message = data.message;
+                                       
+                                       data.previous.forEach(function(previous) {
+                                               details += '<hr><p>' + previous.message + '</p>';
+                                               details += '<br><p>Stacktrace</p><p>' + previous.stacktrace + '</p>';
+                                       });
                                }
                                else {
                                        message = xhr.responseText;
index ff1674a5d022f3413b662ba95e733f9284b25aec..41de8d4127f68423a54e55b7abc06ed180fc2825 100644 (file)
@@ -202,7 +202,7 @@ class AJAXInvokeAction extends AbstractSecureAction {
                        throw new AJAXException($e->getMessage(), AJAXException::BAD_PARAMETERS, $e->getTraceAsString());
                }
                else {
-                       throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString(), [], \wcf\functions\exception\logThrowable($e));
+                       throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString(), [], \wcf\functions\exception\logThrowable($e), $e->getPrevious());
                }
        }
        
index 6f1a7490b52ce9f7c6bb20501c40f5ad3fef3d6b..461df248677a8f8247bcbf4cd20450faee27ef6f 100644 (file)
@@ -56,23 +56,37 @@ class AJAXException extends LoggedException {
         * @param       string          $stacktrace
         * @param       mixed[]         $returnValues
         * @param       string          $exceptionID
+        * @param       \Exception|\Throwable   $previous
         */
-       public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = [], $exceptionID = '') {
+       public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = [], $exceptionID = '', $previous = null) {
                if ($stacktrace === null) $stacktrace = $this->getTraceAsString();
                
                $responseData = [
                        'code' => $errorType,
                        'message' => $message,
+                       'previous' => [],
                        'returnValues' => $returnValues
                ];
                
                // include a stacktrace if:
                // - debug mode is enabled
                // - within ACP and a SystemException was thrown
-               if (WCF::debugModeIsEnabled(false) || WCF::debugModeIsEnabled() && self::INTERNAL_ERROR) {
+               $includeStacktrace = (WCF::debugModeIsEnabled(false) || WCF::debugModeIsEnabled() && self::INTERNAL_ERROR);
+               
+               if ($includeStacktrace) {
                        $responseData['stacktrace'] = nl2br($stacktrace, false);
                }
                
+               if ($includeStacktrace) {
+                       while ($previous) {
+                               $data = ['message' => $previous->getMessage()];
+                               $data['stacktrace'] = nl2br($previous->getTraceAsString(), false);
+                               
+                               $responseData['previous'][] = $data;
+                               $previous = $previous->getPrevious();
+                       }
+               }
+               
                $statusHeader = '';
                switch ($errorType) {
                        case self::MISSING_PARAMETERS: