Esempio n. 1
0
 /**
  * Handles the given Exception.
  *
  * @param Throwable|Exception $exception The Exception to handle
  * @param bool                $showTrace
  */
 public static function handleException($exception, $showTrace = true)
 {
     rex_logger::logException($exception);
     while (ob_get_level()) {
         ob_end_clean();
     }
     $status = rex_response::HTTP_INTERNAL_ERROR;
     if ($exception instanceof rex_http_exception && $exception->getHttpCode()) {
         $status = $exception->getHttpCode();
     }
     rex_response::setStatus($status);
     if (rex::isSetup() || rex::isDebugMode() || ($user = rex_backend_login::createUser()) && $user->isAdmin()) {
         // TODO add a beautiful error page with usefull debugging info
         $buf = '';
         $buf .= '<pre>';
         $buf .= '"' . get_class($exception) . '" thrown in ' . $exception->getFile() . ' on line ' . $exception->getLine() . "\n";
         if ($exception->getMessage()) {
             $buf .= '<b>' . ($exception instanceof ErrorException ? self::getErrorType($exception->getSeverity()) . ': ' : '') . $exception->getMessage() . "</b>\n";
         }
         $cause = $exception->getPrevious();
         while ($cause) {
             $buf .= "\n";
             $buf .= 'caused by ' . get_class($cause) . ' in ' . $cause->getFile() . ' on line ' . $cause->getLine() . "\n";
             if ($cause->getMessage()) {
                 $buf .= '<b>' . ($cause instanceof ErrorException ? self::getErrorType($cause->getSeverity()) . ': ' : '') . $cause->getMessage() . "</b>\n";
             }
             $cause = $cause->getPrevious();
         }
         if ($showTrace) {
             $buf .= "\n";
             $buf .= $exception->getTraceAsString();
         }
         if (!rex::isSetup() && rex::isBackend() && !rex::isSafeMode()) {
             $buf .= "\n\n";
             $buf .= '<a href="' . rex_url::backendPage('packages', ['safemode' => 1]) . '">activate safe mode</a>';
         }
         $buf .= '</pre>';
     } else {
         // TODO small error page, without debug infos
         $buf = 'Oooops, an internal error occured!';
     }
     rex_response::sendContent($buf);
     exit;
 }