* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\Action
- * @since 5.2
+ * @since 5.2
*/
trait TAJAXException {
/**
*/
protected function throwException($e) {
if ($e instanceof InvalidSecurityTokenException) {
- throw new AJAXException(WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.sessionExpired'), AJAXException::SESSION_EXPIRED, $e->getTraceAsString());
+ throw new AJAXException(
+ WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.sessionExpired'),
+ AJAXException::SESSION_EXPIRED,
+ $e->getTraceAsString(),
+ [
+ 'file' => $e->getFile(),
+ 'line' => $e->getLine()
+ ]
+ );
}
else if ($e instanceof PermissionDeniedException) {
- throw new AJAXException(WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS, $e->getTraceAsString());
+ throw new AJAXException(
+ WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'),
+ AJAXException::INSUFFICIENT_PERMISSIONS,
+ $e->getTraceAsString(),
+ [
+ 'file' => $e->getFile(),
+ 'line' => $e->getLine()
+ ]
+ );
}
else if ($e instanceof IllegalLinkException) {
- throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.illegalLink'), AJAXException::ILLEGAL_LINK, $e->getTraceAsString());
+ throw new AJAXException(
+ WCF::getLanguage()->get('wcf.ajax.error.illegalLink'),
+ AJAXException::ILLEGAL_LINK,
+ $e->getTraceAsString(),
+ [
+ 'file' => $e->getFile(),
+ 'line' => $e->getLine()
+ ]
+ );
}
else if ($e instanceof UserInputException) {
// repackage as ValidationActionException
$exception = new ValidateActionException($e->getField(), $e->getType(), $e->getVariables());
- throw new AJAXException($exception->getMessage(), AJAXException::BAD_PARAMETERS, $e->getTraceAsString(), [
- 'errorMessage' => $exception->getMessage(),
- 'errorType' => $e->getType(),
- 'fieldName' => $exception->getFieldName(),
- 'realErrorMessage' => $exception->getErrorMessage()
- ]);
+ throw new AJAXException(
+ $exception->getMessage(),
+ AJAXException::BAD_PARAMETERS,
+ $e->getTraceAsString(),
+ [
+ 'errorMessage' => $exception->getMessage(),
+ 'errorType' => $e->getType(),
+ 'file' => $e->getFile(),
+ 'fieldName' => $e->getFieldName(),
+ 'line' => $e->getLine(),
+ 'realErrorMessage' => $exception->getErrorMessage()
+ ]
+ );
}
else if ($e instanceof ValidateActionException) {
throw new AJAXException($e->getMessage(), AJAXException::BAD_PARAMETERS, $e->getTraceAsString(), [
'errorMessage' => $e->getMessage(),
+ 'file' => $e->getFile(),
'fieldName' => $e->getFieldName(),
+ 'line' => $e->getLine(),
'realErrorMessage' => $e->getErrorMessage()
]);
}
else if ($e instanceof NamedUserException) {
- throw new AJAXException($e->getMessage(), AJAXException::BAD_PARAMETERS, $e->getTraceAsString());
+ throw new AJAXException(
+ $e->getMessage(),
+ AJAXException::BAD_PARAMETERS,
+ $e->getTraceAsString(),
+ [
+ 'file' => $e->getFile(),
+ 'line' => $e->getLine()
+ ]
+ );
}
else {
- throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString(), [], \wcf\functions\exception\logThrowable($e), $e->getPrevious());
+ throw new AJAXException(
+ $e->getMessage(),
+ AJAXException::INTERNAL_ERROR,
+ $e->getTraceAsString(),
+ [
+ 'file' => $e->getFile(),
+ 'line' => $e->getLine()
+ ],
+ \wcf\functions\exception\logThrowable($e),
+ $e->getPrevious()
+ );
}
}
}
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 or
// - within ACP and a SystemException was thrown
$includeStacktrace = WCF::debugModeIsEnabled();
}
- if ($includeStacktrace) {
- $responseData['stacktrace'] = nl2br($stacktrace, false);
+ // extract file and line in which exception was thrown and only include it
+ // if stacktrace is also included
+ $file = $line = null;
+ if (isset($returnValues['file'])) {
+ if ($includeStacktrace) {
+ $file = $returnValues['file'];
+ }
+
+ unset($returnValues['file']);
+ }
+ if (isset($returnValues['line'])) {
+ if ($includeStacktrace) {
+ $line = $returnValues['line'];
+ }
+
+ unset($returnValues['line']);
}
+ $responseData = [
+ 'code' => $errorType,
+ 'file' => $file,
+ 'line' => $line,
+ 'message' => $message,
+ 'previous' => [],
+ 'returnValues' => $returnValues
+ ];
+
if ($includeStacktrace) {
+ $responseData['stacktrace'] = nl2br($stacktrace, false);
+
while ($previous) {
$data = ['message' => $previous->getMessage()];
$data['stacktrace'] = nl2br($previous->getTraceAsString(), false);