From ef5f78cd7b8f69203d288afc896705058ca29e56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 13 Apr 2016 17:58:51 +0200 Subject: [PATCH] Fix exception handling in AJAXInvokeAction --- .../lib/action/AJAXInvokeAction.class.php | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php index e906cc850f..af041af17c 100644 --- a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php @@ -69,6 +69,14 @@ class AJAXInvokeAction extends AbstractSecureAction { $this->throwException($e); } } + catch (\Throwable $e) { + if ($e instanceof AJAXException) { + throw $e; + } + else { + $this->throwException($e); + } + } } /** @@ -97,6 +105,9 @@ class AJAXInvokeAction extends AbstractSecureAction { catch (\Exception $e) { $this->throwException($e); } + catch (\Throwable $e) { + $this->throwException($e); + } $this->executed(); // send JSON-encoded response @@ -151,26 +162,21 @@ class AJAXInvokeAction extends AbstractSecureAction { /** * Throws an previously catched exception while maintaing the propriate stacktrace. * - * @param \Exception $e + * @param \Exception|\Throwable $e * @throws AJAXException * @throws \Exception */ - protected function throwException(\Exception $e) { + protected function throwException($e) { if ($this->inDebugMode) { throw $e; } - // TODO: This needs to be updated to the new exception handling code. - throw $e; - //throw new \Exception('TODO: AJAXInvokeAction::throwException()'); + if ($e instanceof InvalidSecurityTokenException) { throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.sessionExpired'), AJAXException::SESSION_EXPIRED, $e->getTraceAsString()); } else if ($e instanceof 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(), array(), $e->getExceptionID()); - } else if ($e instanceof IllegalLinkException) { throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.illegalLink'), AJAXException::ILLEGAL_LINK, $e->getTraceAsString()); } @@ -193,7 +199,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(), array(), ($e instanceof LoggedException ? $e->getExceptionID() : '')); + throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString(), array(), \wcf\functions\exception\logThrowable($e)); } } -- 2.20.1