getMessage() public method

public getMessage ( )
コード例 #1
0
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     if ($exception->getClass() == MailException::class) {
         return new Response($this->twig->render('CantigaCoreBundle:Exception:mail-exception.html.twig', array('message' => $exception->getMessage())), 501);
     }
     return parent::showAction($request, $exception, $logger);
 }
コード例 #2
0
ファイル: PageController.php プロジェクト: pixocode/noostache
 public function exceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger)
 {
     $viewData = [];
     $viewData['status'] = $exception->getStatusCode();
     $viewData['message'] = $exception->getMessage();
     return $this->render('AppBundle:Exception:error.html.twig', $viewData);
 }
コード例 #3
0
 public function exceptionAction(FlattenException $exception)
 {
     $this->view->status_code = $exception->getStatusCode();
     $this->view->message = $exception->getMessage();
     $this->view->file = $this->getShortFileName($exception->getFile());
     $this->view->line = $exception->getLine();
     $this->view->trace = $this->parseTrace($exception->getTrace());
     return $this->renderTo('@HideksFramework/templates/exception.html');
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $class = $exception->getClass();
     //ignore authentication exceptions
     if (strpos($class, 'Authentication') === false) {
         $env = $this->factory->getEnvironment();
         $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
         $layout = $env == 'prod' ? 'Error' : 'Exception';
         $code = $exception->getStatusCode();
         if ($code === 0) {
             //thrown exception that didn't set a code
             $code = 500;
         }
         // Special handling for oauth and api urls
         if (strpos($request->getUri(), '/oauth') !== false && strpos($request->getUri(), 'authorize') === false || strpos($request->getUri(), '/api') !== false) {
             $dataArray = array('error' => array('message' => $exception->getMessage(), 'code' => $code));
             if ($env == 'dev') {
                 $dataArray['trace'] = $exception->getTrace();
             }
             return new JsonResponse($dataArray, 200);
         }
         if ($request->get('prod')) {
             $layout = 'Error';
         }
         $anonymous = $this->factory->getSecurity()->isAnonymous();
         $baseTemplate = 'MauticCoreBundle:Default:slim.html.php';
         if ($anonymous) {
             if ($templatePage = $this->factory->getTheme()->getErrorPageTemplate($code)) {
                 $baseTemplate = $templatePage;
             }
         }
         $template = "MauticCoreBundle:{$layout}:{$code}.html.php";
         $templating = $this->factory->getTemplating();
         if (!$templating->exists($template)) {
             $template = "MauticCoreBundle:{$layout}:base.html.php";
         }
         $statusText = isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '';
         $url = $request->getRequestUri();
         $urlParts = parse_url($url);
         return $this->delegateView(array('viewParameters' => array('baseTemplate' => $baseTemplate, 'status_code' => $code, 'status_text' => $statusText, 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'isPublicPage' => $anonymous), 'contentTemplate' => $template, 'passthroughVars' => array('error' => array('code' => $code, 'text' => $statusText, 'exception' => $env == 'dev' ? $exception->getMessage() : '', 'trace' => $env == 'dev' ? $exception->getTrace() : ''), 'route' => $urlParts['path'])));
     }
 }
コード例 #5
0
 /**
  * Сериализует исключение и возвращает исключение.
  * 
  * @param Request $request Запрос
  * @param FlattenException $exception Исключение
  * @param DebugLoggerInterface $logger Лог
  * @param string $format Формат сериализации
  * @return Response
  */
 public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'json')
 {
     /** @var \FOS\RestBundle\View\ViewHandler $viewHandler */
     $viewHandler = $this->get('fos_rest.view_handler');
     // Если формат сериализации не поддерживается, то выбирается json
     if ($viewHandler->isFormatTemplating($format)) {
         $format = 'json';
     }
     $view = View::create()->setStatusCode($exception->getStatusCode())->setData(new ExceptionRepresentation($exception->getStatusCode(), $exception->getMessage(), null))->setFormat($format);
     return $viewHandler->handle($view);
 }
コード例 #6
0
 /**
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $status = $exception->getStatusCode();
     $message = $exception->getMessage();
     $previousUrl = $request->headers->get('referer');
     if ($request->getFormat($request->getAcceptableContentTypes()[0]) == 'json') {
         return new JsonResponse(['status' => $status, 'message' => $message]);
     } else {
         return $this->render('exception/404.html.twig', ['status' => $status, 'message' => $message, 'previousUrl' => $previousUrl]);
     }
 }
コード例 #7
0
 /**
  * Converts an Exception to a Response.
  *
  * @param  Request          $request
  * @param  FlattenException $exception
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception)
 {
     if (is_subclass_of($exception->getClass(), 'Pagekit\\Kernel\\Exception\\HttpException')) {
         $title = $exception->getMessage();
     } else {
         $title = __('Whoops, looks like something went wrong.');
     }
     $content = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $response = App::view('system/error.php', compact('title', 'exception', 'content'));
     return App::response($response, $exception->getCode(), $exception->getHeaders());
 }
コード例 #8
0
 public function getContent(FlattenException $exception)
 {
     if ($exception->getStatusCode() == '500') {
         $this->logger->error($exception->getMessage(), ['code' => $exception->getCode(), 'trace' => $exception->getTrace()]);
     }
     switch (true) {
         case 404 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, the page you are looking for could not be found.');
             } else {
                 $title = 'Sorry, the page you are looking for could not be found.';
             }
             break;
         case 403 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, you do have access to the page you are looking for.');
             } else {
                 $title = 'Sorry, you do have access to the page you are looking for.';
             }
             break;
         case 500 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Whoops, looks like something went wrong.');
             } else {
                 $title = 'Whoops, looks like something went wrong.';
             }
             break;
         case 503 === $exception->getStatusCode():
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Sorry, site is currently undergoing maintenance, come back soon.');
             } else {
                 $title = 'Sorry, site is currently undergoing maintenance, come back soon.';
             }
             break;
         case isset(Response::$statusTexts[$exception->getStatusCode()]):
             $title = $exception->getStatusCode() . ' : ' . Response::$statusTexts[$exception->getStatusCode()];
             break;
         default:
             if (null !== $this->translator) {
                 $title = $this->translator->trans('Whoops, looks like something went wrong.');
             } else {
                 $title = 'Whoops, looks like something went wrong.';
             }
     }
     $content = parent::getContent($exception);
     $start = strpos($content, '</h1>');
     $content = '<div id="sf-resetcontent" class="sf-reset">' . '<h1><span>' . $title . '</span></h1>' . substr($content, $start + 5);
     return $content;
 }
コード例 #9
0
 public function exceptionAction(Request $request, FlattenException $exception)
 {
     $status = $exception->getStatusCode();
     $message = $status && $status < 500 ? $exception->getMessage() : Translate::t("Sorry, there has been an internal error. The administrators have been notified and will fix this as soon as possible.");
     try {
         $reqDetails = $this->load($request);
         $pageDetails = $this->get("agit.page")->getPage("_exception");
         $response = $this->createResponse($pageDetails, $reqDetails, ["message" => $message]);
     } catch (Exception $e) {
         $response = $this->render("AgitPageBundle:Special:exception.html.twig", ["locale" => "en_GB", "message" => $message]);
     }
     $response->setStatusCode($status);
     $response->headers->set("X-Frame-Options", "SAMEORIGIN");
     return $response;
 }
コード例 #10
0
 /**
  * Converts an Exception to a Response.
  *
  * @param  Request              $request
  * @param  FlattenException     $exception
  * @param  DebugLoggerInterface $logger
  * @param  string               $_format
  * @throws \InvalidArgumentException
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
 {
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     switch ($exception->getClass()) {
         case 'Pagekit\\Component\\Session\\Csrf\\Exception\\BadTokenException':
             $title = __('Invalid CSRF token.');
             break;
         case 'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException':
             $title = __('Sorry, the page you are looking for could not be found.');
             break;
         case 'Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException':
             $title = $exception->getMessage();
             break;
         default:
             $title = __('Whoops, looks like something went wrong.');
     }
     $response = $this['view']->render('extension://system/theme/templates/error.razr', compact('title', 'exception', 'currentContent'));
     return $this['response']->create($response, $exception->getStatusCode(), $exception->getHeaders());
 }
コード例 #11
0
 public function exceptionAction(FlattenException $exception)
 {
     $msg = 'Something went wrong! (' . $exception->getMessage() . ')';
     return new Response($msg, $exception->getStatusCode());
 }
コード例 #12
0
 /**
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handleException(FlattenException $exception)
 {
     return new Response($exception->getMessage());
 }
コード例 #13
0
 /**
  * This method is a temporary port of _drupal_decode_exception().
  *
  * @todo This should get refactored. FlattenException could use some
  *   improvement as well.
  *
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *  The flattened exception.
  *
  * @return array
  *   An array of string-substitution tokens for formatting a message about the
  *   exception.
  */
 protected function decodeException(FlattenException $exception)
 {
     $message = $exception->getMessage();
     $backtrace = $exception->getTrace();
     // This value is missing from the stack for some reason in the
     // FlattenException version of the backtrace.
     $backtrace[0]['line'] = $exception->getLine();
     // For database errors, we try to return the initial caller,
     // skipping internal functions of the database layer.
     if (strpos($exception->getClass(), 'DatabaseExceptionWrapper') !== FALSE) {
         // A DatabaseExceptionWrapper exception is actually just a courier for
         // the original PDOException.  It's the stack trace from that exception
         // that we care about.
         $backtrace = $exception->getPrevious()->getTrace();
         $backtrace[0]['line'] = $exception->getLine();
         // The first element in the stack is the call, the second element gives us the caller.
         // We skip calls that occurred in one of the classes of the database layer
         // or in one of its global functions.
         $db_functions = array('db_query', 'db_query_range');
         while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && (strpos($caller['namespace'], 'Drupal\\Core\\Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions)) {
             // We remove that call.
             array_shift($backtrace);
         }
     }
     $caller = Error::getLastCaller($backtrace);
     return array('%type' => $exception->getClass(), '!message' => String::checkPlain($message), '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], 'severity_level' => WATCHDOG_ERROR);
 }
コード例 #14
0
ファイル: Art.php プロジェクト: surfnet/stepup-bundle
 /**
  * @param FlattenException $exception
  * @return string
  */
 public static function forFlattenException(FlattenException $exception)
 {
     return self::calculateArt($exception->getClass(), $exception->getMessage());
 }
コード例 #15
0
 /**
  * Check last send time
  *
  * @param  FlattenException $exception
  * @return bool
  */
 private function checkRepeat(FlattenException $exception)
 {
     $key = md5($exception->getMessage() . ':' . $exception->getLine() . ':' . $exception->getFile());
     $file = $this->errorsDir . '/' . $key;
     $time = is_file($file) ? file_get_contents($file) : 0;
     if ($time < time()) {
         file_put_contents($file, time() + $this->repeatTimeout);
         return false;
     }
     return true;
 }
コード例 #16
0
    /**
     * Gets the HTML content associated with the given exception.
     *
     * @param FlattenException $exception A FlattenException instance
     *
     * @return string The content as a string
     */
    public function getContent(FlattenException $exception)
    {
        switch ($exception->getStatusCode()) {
            case 404:
                $title = 'Sorry, the page you are looking for could not be found.';
                break;
            default:
                $title = 'Whoops, looks like something went wrong. 1 ' . $exception->getMessage();
        }
        $content = '';
        if ($this->debug) {
            try {
                $count = count($exception->getAllPrevious());
                $total = $count + 1;
                foreach ($exception->toArray() as $position => $e) {
                    $ind = $count - $position + 1;
                    $class = $this->formatClass($e['class']);
                    $message = nl2br($this->escapeHtml($e['message']));
                    $content .= sprintf(<<<EOF
                        <h2 class="block_exception clear_fix">
                            <span class="exception_counter">%d/%d</span>
                            <span class="exception_title">%s%s:</span>
                            <span class="exception_message">%s</span>
                        </h2>
                        <div class="block">
                            <ol class="traces list_exception">

EOF
, $ind, $total, $class, $this->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']), $message);
                    foreach ($e['trace'] as $trace) {
                        $content .= '       <li>';
                        if ($trace['function']) {
                            $content .= sprintf('at %s%s%s(%s)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
                        }
                        if (isset($trace['file']) && isset($trace['line'])) {
                            $content .= $this->formatPath($trace['file'], $trace['line']);
                        }
                        $content .= "</li>\n";
                    }
                    $content .= "    </ol>\n</div>\n";
                }
            } catch (\Exception $e) {
                // something nasty happened and we cannot throw an exception anymore
                if ($this->debug) {
                    $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
                } else {
                    $title = 'Whoops, looks like something went wrong.';
                }
            }
        }
        return <<<EOF
            <div id="sf-resetcontent" class="sf-reset">
                <h1>{$title}</h1>
                {$content}
            </div>
EOF;
    }