Example #1
0
 /**
  * Change the router state according to the error Code
  * @param string $errorRouteId
  * @param \Exception $error
  * @throws Exception
  * @throws \Exception
  */
 public function route($errorCode, $error)
 {
     // Router knows a route for this error code
     if (isset($this->routeId[$errorCode])) {
         $errorRouteId = $this->routeId[$errorCode];
     } else {
         $errorRouteId = null;
     }
     if ($this->_router->ruleExists($errorRouteId)) {
         // There is a specific route for this error code
         $errorRoute = $errorRouteId;
     } elseif ($this->_router->ruleExists(self::ROUTE_ALL_ERROR)) {
         // There is a default route for all errors
         $errorRoute = self::ROUTE_ALL_ERROR;
     } else {
         // No route for error, do nothing
         $errorRoute = null;
     }
     if ($errorRoute !== null) {
         try {
             // Prepare redirecting in the router
             $this->_router->route($this->_router->getPrefix() . '/' . $errorRoute);
             $this->_router->setVariable('err', $error);
         } catch (\Exception $e) {
             // The router is unable to route the error
             throw new Exception('Unable to handle error ' . $e, 0, $e);
         }
     } else {
         // There is no error route for this error code, just transfert the exception
         throw $error;
     }
 }