示例#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;
 }
示例#2
0
 public static function delete($path)
 {
     $fullpath = self::PATH . self::getPath($path);
     $error = null;
     try {
         $socket = rex_socket::factory(self::HOST, self::PORT, self::SSL);
         $socket->setPath($fullpath);
         $response = $socket->doDelete();
         if ($response->isOk()) {
             $data = json_decode($response->getBody(), true);
             if (!isset($data['error']) || !is_string($data['error'])) {
                 return;
             }
             $error = rex_i18n::msg('install_webservice_error') . '<br />' . $data['error'];
         }
     } catch (rex_socket_exception $e) {
         rex_logger::logException($e);
     }
     if (!$error) {
         $error = rex_i18n::msg('install_webservice_unreachable');
     }
     throw new rex_functional_exception($error);
 }