Fix exception handling in AJAXInvokeAction
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 13 Apr 2016 15:58:51 +0000 (17:58 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 13 Apr 2016 16:00:36 +0000 (18:00 +0200)
wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php

index e906cc850f5d08f52489cbc54e989819d0a3fbb0..af041af17cc5d043bc23299bda42649416aa25ab 100644 (file)
@@ -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));
                }
        }