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;
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());
}
}
* @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: