Handle NamedUserExceptions in RequestHandler
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 29 Sep 2015 20:47:03 +0000 (22:47 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 1 Dec 2015 21:15:48 +0000 (22:15 +0100)
wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index 1e00a3b2d517d48657186f541b57c0a7c59f1072..cdd73edf095e5aef5e6ec0f78ba8719606996372 100644 (file)
@@ -4,6 +4,7 @@ use wcf\system\application\ApplicationHandler;
 use wcf\system\cache\builder\ControllerCacheBuilder;
 use wcf\system\exception\AJAXException;
 use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\NamedUserException;
 use wcf\system\exception\SystemException;
 use wcf\system\menu\page\PageMenu;
 use wcf\system\SingletonFactory;
@@ -102,41 +103,47 @@ class RequestHandler extends SingletonFactory {
         * @param       boolean         $isACPRequest
         */
        public function handle($application = 'wcf', $isACPRequest = false) {
-               $this->isACPRequest = $isACPRequest;
-               
-               if (!RouteHandler::getInstance()->matches()) {
-                       if (ENABLE_DEBUG_MODE) {
-                               throw new SystemException("Cannot handle request, no valid route provided.");
-                       }
-                       else {
-                               throw new IllegalLinkException();
-                       }
-               }
-               
-               // build request
-               $this->buildRequest($application);
-               
-               // handle offline mode
-               if (!$isACPRequest && defined('OFFLINE') && OFFLINE) {
-                       if (!WCF::getSession()->getPermission('admin.general.canViewPageDuringOfflineMode') && !$this->activeRequest->isAvailableDuringOfflineMode()) {
-                               if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
-                                       throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS);
+               try {
+                       $this->isACPRequest = $isACPRequest;
+                       
+                       if (!RouteHandler::getInstance()->matches()) {
+                               if (ENABLE_DEBUG_MODE) {
+                                       throw new SystemException("Cannot handle request, no valid route provided.");
                                }
                                else {
-                                       @header('HTTP/1.1 503 Service Unavailable');
-                                       WCF::getTPL()->assign(array(
-                                               'templateName' => 'offline',
-                                               'templateNameApplication' => 'wcf'
-                                       ));
-                                       WCF::getTPL()->display('offline');
+                                       throw new IllegalLinkException();
+                               }
+                       }
+                       
+                       // build request
+                       $this->buildRequest($application);
+                       
+                       // handle offline mode
+                       if (!$isACPRequest && defined('OFFLINE') && OFFLINE) {
+                               if (!WCF::getSession()->getPermission('admin.general.canViewPageDuringOfflineMode') && !$this->activeRequest->isAvailableDuringOfflineMode()) {
+                                       if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
+                                               throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS);
+                                       }
+                                       else {
+                                               @header('HTTP/1.1 503 Service Unavailable');
+                                               WCF::getTPL()->assign(array(
+                                                       'templateName' => 'offline',
+                                                       'templateNameApplication' => 'wcf'
+                                               ));
+                                               WCF::getTPL()->display('offline');
+                                       }
+                                       
+                                       exit;
                                }
-                               
-                               exit;
                        }
+                       
+                       // start request
+                       $this->activeRequest->execute();
+               }
+               catch (NamedUserException $e) {
+                       $e->show();
+                       exit;
                }
-               
-               // start request
-               $this->activeRequest->execute();
        }
        
        /**