}
if (!this._suppressErrors && $showError !== false) {
- $('<div class="ajaxDebugMessage"><p>' + $data.message + '</p><p>Stacktrace:</p><p>' + $data.stacktrace + '</p></div>').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') });
+ var $details = '';
+ 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>';
+
+ $('<div class="ajaxDebugMessage"><p>' + $data.message + '</p>' + $details + '</div>').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') });
}
}
// failed to parse JSON
<?php
namespace wcf\action;
+use wcf\system\exception\LoggedException;
+
use wcf\system\exception\AJAXException;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS, $e->getTraceAsString());
}
else if ($e instanceof SystemException) {
- throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->__getTraceAsString());
+ throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->__getTraceAsString(), array(), $e->getExceptionID());
}
else if ($e instanceof UserInputException) {
// repackage as ValidationActionException
));
}
else {
- throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString());
+ throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString(), array(), ($e instanceof LoggedException ? $e->getExceptionID() : ''));
}
}
* @param string $message
* @param boolean $isDoomsday
* @param string $stacktrace
+ * @param array $returnValues
+ * @param string $exceptionID
* @param array<mixed> $returnValues
*/
- public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = array()) {
+ public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = array(), $exceptionID = '') {
if ($stacktrace === null) $stacktrace = $this->getTraceAsString();
if (WCF::debugModeIsEnabled()) {
header('HTTP/1.0 503 Service Unavailable');
$responseData['code'] = self::INTERNAL_ERROR;
+ $responseData['exceptionID'] = $exceptionID;
if (!WCF::debugModeIsEnabled()) {
$responseData['message'] = WCF::getLanguage()->get('wcf.ajax.error.internalError');
}
-
- $this->logError();
break;
}
* @category Community Framework
*/
class LoggedException extends \Exception {
+ /**
+ * exception id
+ * @var string
+ */
+ protected $exceptionID = '';
+
/**
* ignore disabled debug mode
* @var boolean
return $e->getMessage();
}
+ /**
+ * Returns exception id
+ *
+ * @return string
+ */
+ public function getExceptionID() {
+ if (empty($this->exceptionID)) {
+ $this->logError();
+ }
+
+ return $this->exceptionID;
+ }
+
/**
* Writes an error to log file.
*/
protected function logError() {
+ if (!empty($this->exceptionID)) {
+ return;
+ }
+
$logFile = WCF_DIR . 'log/' . date('Y-m-d', TIME_NOW) . '.txt';
// try to create file
"Stacktrace: \n ".implode("\n ", explode("\n", $e->getTraceAsString()))."\n";
// calculate Exception-ID
- $id = StringUtil::getHash($message);
- $message = "<<<<<<<<".$id."<<<<\n".$message."<<<<\n\n";
+ $this->exceptionID = StringUtil::getHash($message);
+ $message = "<<<<<<<<".$this->exceptionID."<<<<\n".$message."<<<<\n\n";
// append
@file_put_contents($logFile, $message, FILE_APPEND);
-
- return $id;
}
}
* @see wcf\system\exception\IPrintableException::show()
*/
public function show() {
- // log error
- $exceptionID = $this->logError();
-
// send status code
@header('HTTP/1.1 503 Service Unavailable');
<h2>Information:</h2>
<p>
- <b>id:</b> <code><?php echo $exceptionID; ?></code><br>
+ <b>id:</b> <code><?php echo $this->getExceptionID(); ?></code><br>
<b>error message:</b> <?php echo StringUtil::encodeHTML($this->_getMessage()); ?><br>
<b>error code:</b> <?php echo intval($e->getCode()); ?><br>
<?php echo $this->information; ?>
<div>
<h2>Information:</h2>
<p>
- <b>id:</b> <code><?php echo $exceptionID; ?></code><br>
+ <b>id:</b> <code><?php echo $this->getExceptionID(); ?></code><br>
Send this ID to the administrator of this website to report this issue.
</p>
</div>