/**
  * 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;
 }
    /**
     * 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;
 }
Example #4
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;
 }
Example #5
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;
 }
Example #6
0
 /**
  * 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();
     $response = $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));
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
 /**
  * @param Request $request
  * @param FlattenException $exception
  * @param DebugLoggerInterface $logger
  * @return \GoIntegro\Hateoas\Http\JsonResponse
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = NULL)
 {
     $error = new ErrorObject();
     $error->status = $exception->getStatusCode();
     $error->title = $exception->getMessage();
     $error->code = $exception->getCode();
     $serializer = new ErrorSerializer($error);
     if (500 == $error->status && NULL != $logger) {
         $logger->error(sprintf(self::ERROR_LOG_MESSAGE_PATTERN, $error->title, $exception->getFile(), $exception->getLine(), $error->id));
     }
     return $this->createNoCacheResponse($serializer->serialize(), $error->status, $exception->getHeaders());
 }
 /**
  * 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]);
     if (404 == $code) {
         if ($this->container->get('request')->isXmlHttpRequest()) {
             $response = new Response('You should not do that.');
         } else {
             $response = $this->container->get('http_kernel')->forward('LichessOpeningBundle:Hook:index');
         }
     } 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 = $this->container->get('templating')->renderResponse('LichessBundle:Exception:error.html.twig', $params);
         }
     }
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }