Basically, this class removes all objects from the trace.
Deprecation: Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead.
Author: Fabien Potencier (fabien@symfony.com)
    /**
     * Converts an Exception to a Response.
     *
     * @param FlattenException     $exception A FlattenException instance
     * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
     * @param string               $format    The format to use for rendering (html, xml, ...)
     *
     * @throws \InvalidArgumentException When the exception template does not exist
     */
    public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
    {
        $this->container->get('request')->setRequestFormat($format);

        // the count variable avoids an infinite loop on
        // some Windows configurations where ob_get_level()
        // never reaches 0
        $count = 100;
        $currentContent = '';
        while (ob_get_level() && --$count) {
            $currentContent .= ob_get_clean();
        }

        $templating = $this->container->get('templating');
        $code = $exception->getStatusCode();

        $response = $templating->renderResponse(
            $this->findTemplate($templating, $format, $code, $this->container->get('kernel')->isDebug()),
            array(
                'status_code'    => $code,
                'status_text'    => Response::$statusTexts[$code],
                'exception'      => $exception,
                'logger'         => $logger,
                'currentContent' => $currentContent,
            )
        );

        $response->setStatusCode($code);
        $response->headers->replace($exception->getHeaders());

        return $response;
    }
 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     // the count variable avoids an infinite loop on
     // some Windows configurations where ob_get_level()
     // never reaches 0
     $count = 100;
     $currentContent = '';
     while (ob_get_level() && --$count) {
         $currentContent .= ob_get_clean();
     }
     $name = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
     if ($this->container->get('kernel')->isDebug() && 'html' == $format) {
         $name = 'exception_full';
     }
     $template = 'FrameworkBundle:Exception:' . $name . '.' . $format . '.twig';
     $templating = $this->container->get('templating');
     if (!$templating->exists($template)) {
         $this->container->get('request')->setRequestFormat('html');
         $template = 'FrameworkBundle:Exception:' . $name . '.html.twig';
     }
     $code = $exception->getStatusCode();
     $response = $templating->renderResponse($template, array('status_code' => $code, 'status_text' => Response::$statusTexts[$code], 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent));
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
 /**
  * Converts an Exception to a Response.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $request->setRequestFormat($format);
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $code = $exception->getStatusCode();
     return new Response($this->twig->render($this->findTemplate($request, $format, $code, $this->debug), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     $code = $exception->getStatusCode();
     $params = array('status_code' => $code, 'status_text' => Response::$statusTexts[$code]);
     try {
         $params['auth'] = $this->container->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED');
     } catch (\Exception $e) {
         $params['auth'] = false;
     }
     $templating = $this->container->get('templating');
     if (404 == $code) {
         if ($this->container->get('request')->isXmlHttpRequest()) {
             $response = new Response('You should not do that.');
         } else {
             $response = $templating->renderResponse('LichessBundle:Exception:notFound.html.twig', $params);
         }
     } else {
         if ($this->container->get('request')->isXmlHttpRequest()) {
             $response = new Response('Something went terribly wrong.');
         } else {
             $params['url'] = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['REQUEST_URI'];
             $response = $templating->renderResponse('LichessBundle:Exception:error.html.twig', $params);
         }
     }
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $isDebug = $this->container->get('kernel')->isDebug();
     $this->request = $this->container->get('request');
     //TODO: there might be a case in the future that we will use other formats, but right now let's make this simple and always use an html template
     $this->request->setRequestFormat('html');
     $currentContent = $this->getAndCleanOutputBuffering();
     $errorMessages = $this->container->getParameter('error_messages');
     $templating = $this->container->get('templating');
     $code = $exception->getStatusCode();
     $factory = $this->container->get('form.factory');
     $form = $factory->create(new ErrorReportFormType());
     if ($this->request->server->has('PATH_INFO')) {
         $pathInfo = $this->request->server->get('PATH_INFO');
     } else {
         $pathInfo = $this->request->server->get('REQUEST_URI');
     }
     if (\preg_match('/admin/i', $pathInfo)) {
         $statusTextDescriptions = $errorMessages['admin'];
     } elseif (\preg_match('/institution/i', $pathInfo)) {
         $statusTextDescriptions = $errorMessages['institution'];
     } else {
         $statusTextDescriptions = $errorMessages['frontend'];
     }
     if ($this->request->server->has('HTTP_REFERER')) {
         if (\preg_match('/healthcareabroad/i', $this->request->server->get('HTTP_REFERER'))) {
             $referer = $this->request->server->get('HTTP_REFERER');
         }
     } else {
         $referer = null;
     }
     return $templating->renderResponse($this->findTemplate($templating, $format, $code, $isDebug, $referer), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) && Response::$statusTexts[$code] ? Response::$statusTexts[$code] : 'Error', 'status_text_details' => isset($statusTextDescriptions[$code]) ? $statusTextDescriptions[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'form' => $form->createView(), 'referer' => $referer));
 }
Exemple #6
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.';
        }
        $content = '';
        if ($this->debug) {
            try {
                $count = count($exception->getAllPrevious());
                $total = $count + 1;
                foreach ($exception->toArray() as $position => $e) {
                    $ind = $count - $position + 1;
                    $class = $this->abbrClass($e['class']);
                    $message = nl2br($e['message']);
                    $content .= sprintf(<<<EOF
                        <div class="block_exception clear_fix">
                            <h2><span>%d/%d</span> %s: %s</h2>
                        </div>
                        <div class="block">
                            <ol class="traces list_exception">

EOF
, $ind, $total, $class, $message);
                    foreach ($e['trace'] as $trace) {
                        $content .= '       <li>';
                        if ($trace['function']) {
                            $content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
                        }
                        if (isset($trace['file']) && isset($trace['line'])) {
                            if ($linkFormat = ini_get('xdebug.file_link_format')) {
                                $link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat);
                                $content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
                            } else {
                                $content .= sprintf(' in %s line %s', $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($exception), $exception->getMessage());
                } else {
                    $title = 'Whoops, looks like something went wrong.';
                }
            }
        }
        return <<<EOF
            <div id="sf-resetcontent" class="sf-reset">
                <h1>{$title}</h1>
                {$content}
            </div>
EOF;
    }
 /**
  * Converts an Exception to a Response.
  *
  * A "showException" request parameter can be used to force display of an error page (when set to false) or
  * the exception page (when true). If it is not present, the "debug" value passed into the constructor will
  * be used.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     return new Response($this->twig->render($this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     $currentContent = $this->getAndCleanOutputBuffering();
     $templating = $this->container->get('templating');
     $code = $exception->getStatusCode();
     return $templating->renderResponse($this->findTemplate($templating, $format, $code, $this->container->get('kernel')->isDebug()), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent));
 }
 public function exceptionAction(FlattenException $exception)
 {
     // $msg = 'Something went wrong! ('.$exception->getMessage().')';
     //
     // return new Response($msg, $exception->getStatusCode());
     $msg = 'Something went wrong!';
     return new Response($msg, $exception->getStatusCode());
 }
Exemple #10
0
 public function errorAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     $response = new Response('Something is wrong');
     $code = $exception->getStatusCode();
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
Exemple #11
0
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $statusCode = $exception->getStatusCode();
     $statusText = $exception->getMessage();
     $response = $this->render('GitonomyWebsiteBundle:Error:error.html.twig', array('status_code' => $statusCode, 'status_text' => $statusText));
     $response->setStatusCode($statusCode);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
 /**
  * Converts an Exception to a Response.
  *
  * @param Request $request The request
  * @param FlattenException $exception A FlattenException instance
  * @param DebugLoggerInterface $logger A DebugLoggerInterface instance
  *
  * @param string $_format
  * @return JsonResponse
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
 {
     $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $wrapper = new ExceptionWrapper();
     $wrapper->setCode($exception->getCode());
     $wrapper->setMessage($exception->getMessage());
     $wrapper->setStatusCode($exception->getStatusCode());
     $wrapper->setTrace($this->debug ? $exception->getTrace() : array());
     return $wrapper->getResponse();
 }
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     // IF an API URL, show the result as JSON - otherwise show HTML format
     $format = strncmp($request->getPathInfo(), '/api/', strlen('/api/')) == 0 ? 'json' : 'html';
     $request->setRequestFormat($format);
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     return new Response($this->twig->render($this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  * @param Boolean              $embedded  Whether the rendered Response will be embedded or not
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function exceptionAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html', $embedded = false)
 {
     $this->container->get('request')->setRequestFormat($format);
     $currentContent = '';
     while (false !== ($content = ob_get_clean())) {
         $currentContent .= $content;
     }
     $response = $this->container->get('templating')->renderResponse('FrameworkBundle:Exception:' . ($this->container->get('kernel')->isDebug() ? 'exception' : 'error'), array('exception' => new SafeDecorator($exception), 'logger' => $logger, 'currentContent' => $currentContent, 'embedded' => $embedded));
     $response->setStatusCode($exception->getStatusCode());
     return $response;
 }
 protected function getStatusCode(FlattenException $exception)
 {
     switch ($exception->getClass()) {
         case 'Symfony\\Component\\Security\\Exception\\AccessDeniedException':
             return 403;
         case 'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException':
             return 404;
         default:
             return 500;
     }
 }
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $code = $exception->getStatusCode();
     if (!$this->debug) {
         $template = new TemplateReference(sprintf('@SymEdit/Exception/%d.html.twig', $code));
         if ($this->templateExists($template)) {
             return new Response($this->twig->render($template, ['status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger]));
         }
     }
     return parent::showAction($request, $exception, $logger, $format);
 }
 /**
  * Converts an Exception to a Response.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $_format   The format to use for rendering (html, xml, ...)
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
 {
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $code = $exception->getStatusCode();
     if ($this->debug === false) {
         $page = $this->em->getRepository('VictoireTwigBundle:ErrorPage')->findOneByCode($code);
         if ($page) {
             return $this->forward('VictoireTwigBundle:ErrorPage:show', array('code' => $page->getCode()));
         }
     }
     return new Response($this->twig->render($this->findTemplate($request, $_format, $code, $this->debug), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
 /**
  * {@inheritdoc}
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $code = $exception->getStatusCode();
     $showException = $request->attributes->get('showException', $this->debug);
     $template = $this->requestAnalyzer->getWebspace()->getTheme()->getErrorTemplate($code);
     if ($showException || $request->getRequestFormat() !== 'html' || $template === null) {
         return parent::showAction($request, $exception, $logger);
     }
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $parameter = ['status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'currentContent' => $currentContent];
     $data = $this->parameterResolver->resolve($parameter, $this->requestAnalyzer);
     return new Response($this->twig->render($template, $data), $code);
 }
 /**
  * {@inheritDoc}
  * @see Symfony\Bundle\TwigBundle\Controller\ExceptionController::showAction
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     if ($exception->getStatusCode() != 404 || $request->getRequestFormat() != 'html') {
         return parent::showAction($request, $exception, $logger);
     }
     // 404 html
     $randomLine = $this->lineRepo->getRandom(1)[0];
     // from parent
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     return new Response($this->twig->render($this->findTemplate($request, $request->getRequestFormat(), $code, $showException), ['random_line' => $randomLine, 'status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent]));
 }
 /**
  * @param Request              $request
  * @param FlattenException     $exception
  * @param DebugLoggerInterface $logger
  * @param string               $_format
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
 {
     $code = $exception->getStatusCode();
     if (404 !== $code) {
         return parent::showAction($request, $exception, $logger, $_format);
     }
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $groupedSuggestions = array();
     foreach ($this->suggestionProviders as $item) {
         $suggestions = $item['provider']->create($request);
         $groupedSuggestions[$item['group']] = isset($groupedSuggestions[$item['group']]) ? array_merge($groupedSuggestions[$item['group']], $suggestions) : $suggestions;
     }
     return new Response($this->twig->render($this->findTemplate($request, $_format, $code, $this->debug), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'best_matches' => $groupedSuggestions)), $code);
 }
 /**
  * @param Request              $request
  * @param FlattenException     $exception
  * @param DebugLoggerInterface $logger
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     /** @var Translator $translator */
     $translator = $this->get('translator');
     $message = $translator->trans('error.messages.generic');
     // check if the error is whitelisted to overrule the message
     if (in_array($exception->getClass(), $this->container->getParameter('sumo_coders_framework_error.show_messages_for'))) {
         $message = $exception->getMessage();
     }
     // translate page not found messages
     if ('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException' == $exception->getClass()) {
         $message = $translator->trans('error.messages.noRouteFound');
     }
     return $this->render('::error.html.twig', array('status_code' => $exception->getStatusCode(), 'status_text' => $message));
 }
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     $request = $event->getRequest();
     $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     } catch (\Exception $e) {
         $this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
         // set handling to false otherwise it wont be able to handle further more
         $handling = false;
         // re-throw the exception from within HttpKernel as this is a catch-all
         return;
     }
     $event->setResponse($response);
     $handling = false;
 }
 /**
  * @dataProvider flattenDataProvider
  */
 public function testFlattenHttpException(\Exception $exception, $statusCode)
 {
     $flattened = FlattenException::create($exception);
     $this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
     $this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
     $this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception');
 }
 public function testException()
 {
     $message = 'THIS IS THE ERROR MESSAGE';
     $e = new \Exception($message);
     $this->assertStringMatchesFormat("%A{$message}%A", HtmlUtilities::exception($e));
     $this->assertStringMatchesFormat("%A{$message}%A", HtmlUtilities::exception(FlattenException::create($e)));
 }
 /**
  * Converts an Exception to a Response to be able to render a Victoire view.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $_format   The format to use for rendering (html, xml, ...)
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  *
  * @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));
     $code = $exception->getStatusCode();
     //get request extension
     $uriArray = explode('/', rtrim($request->getRequestUri(), '/'));
     $matches = preg_match('/^.*(\\..*)$/', array_pop($uriArray), $matches);
     //if in production environment and the query is not a file
     if ($this->debug === false && 0 === $matches) {
         $page = $this->em->getRepository('VictoireTwigBundle:ErrorPage')->findOneByCode($code);
         if ($page) {
             return $this->forward('VictoireTwigBundle:ErrorPage:show', ['code' => $page->getCode()]);
         }
     }
     return new Response($this->twig->render($this->findTemplate($request, $_format, $code, $this->debug), ['status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent]));
 }
Exemple #26
0
 /**
  * Creates the error Response associated with the given Exception.
  *
  * @param \Exception|FlattenException $exception An \Exception instance
  *
  * @return Response A Response instance
  */
 public function createResponse($exception)
 {
     $content = '';
     $title = '';
     try {
         if (!$exception instanceof FlattenException) {
             $exception = FlattenException::create($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.';
         }
         if ($this->debug) {
             $content = $this->getContent($exception);
         }
     } catch (\Exception $e) {
         // something nasty happened and we cannot throw an exception here anymore
         if ($this->debug) {
             $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
         } else {
             $title = 'Whoops, looks like something went wrong.';
         }
     }
     return new Response($this->decorate($content, $title), $exception->getStatusCode());
 }
Exemple #27
0
 public function handle(Event $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
         return false;
     }
     $exception = $event->getParameter('exception');
     $request = $event->getParameter('request');
     if (null !== $this->logger) {
         $this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
     } else {
         error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     }
     $logger = null !== $this->logger ? $this->logger->getDebugLogger() : null;
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $logger, 'format' => 0 === strncasecmp(PHP_SAPI, 'cli', 3) ? 'txt' : $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     try {
         $response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     } catch (\Exception $e) {
         if (null !== $this->logger) {
             $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
         }
         // re-throw the exception as this is a catch-all
         throw new \RuntimeException('Exception thrown when handling an exception.', 0, $e);
     }
     $event->setReturnValue($response);
     return true;
 }
 private function saveDebugInformation(\Exception $ex = null)
 {
     if (!$this->input->hasOption('jms-job-id') || null === ($jobId = $this->input->getOption('jms-job-id'))) {
         return;
     }
     $this->getConnection()->executeUpdate("UPDATE jms_jobs SET stackTrace = :trace, memoryUsage = :memoryUsage, memoryUsageReal = :memoryUsageReal WHERE id = :id", array('id' => $jobId, 'memoryUsage' => memory_get_peak_usage(), 'memoryUsageReal' => memory_get_peak_usage(true), 'trace' => serialize($ex ? FlattenException::create($ex) : null)));
 }
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     if ('Trez\\LogicielTrezBundle\\Exception\\LockedException' === $exception->getClass()) {
         $this->session->getFlashBag()->set('error', "Vous ne pouvez pas éditer un exercice/budget verrouillé ou ses fils");
         return new RedirectResponse($this->request->getRequestUri(), 302);
     }
     if ('Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException' === $exception->getClass()) {
         $this->session->getFlashBag()->set('error', "Vous n'avez pas les privilèges nécessaires pour effectuer cette action !");
         if ($this->securityContext->isGranted('ROLE_USER') === true) {
             return new Response($this->twig->render('TrezLogicielTrezBundle:Default:index.html.twig', array()));
         } else {
             return new Response("Vous n'avez pas les privilèges nécessaires pour afficher cette page !");
         }
     }
     // else default behavior
     return parent::showAction($exception, $logger, $format);
 }
 public function testCollect()
 {
     $e = new \Exception('foo', 500);
     $c = new ExceptionStatsCollector('prefix', $this->mockStatsDFactory('prefix.exception.500'));
     $flattened = FlattenException::create($e);
     $trace = $flattened->getTrace();
     $c->collect(new Request(), new Response(), $e);
 }