getStatusCode() public method

public getStatusCode ( )
    /**
     * 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);
     $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;
 }
Example #3
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.
  *
  * @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));
     $code = $exception->getStatusCode();
     if ($exception->GetClass() == 'UCI\\Boson\\ExcepcionesBundle\\Exception\\LocalException') {
         $arrayRutaFile = explode(DIRECTORY_SEPARATOR, $exception->getFile());
         $strExtraer = "";
         for ($i = count($arrayRutaFile) - 1; $i >= 0; $i--) {
             if (preg_match('/[a-zA-Z0-9]Bundle$/', $arrayRutaFile[$i]) == 1) {
                 $direccionBundle = explode($strExtraer, $exception->getFile())[0];
                 $direccionFileExcepciones = $direccionBundle . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "config";
                 if (is_dir($direccionFileExcepciones)) {
                     break;
                 }
             }
             $strExtraer = DIRECTORY_SEPARATOR . $arrayRutaFile[$i] . $strExtraer;
         }
         $showInProd = false;
         $values = $this->getArrayExcepcionesInFile($direccionFileExcepciones);
         foreach ($values as $key => $excp) {
             if ($key == $exception->getCode() && array_key_exists('show_in_prod', $excp)) {
                 $showInProd = $excp['show_in_prod'];
             }
         }
         return new Response($this->twig->render((string) $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'show_in_prod' => $showInProd, 'logger' => $logger, 'currentContent' => $currentContent)));
     }
     return new Response($this->twig->render((string) $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
 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));
 }
 /**
  * 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, ...)
  *
  * @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));
 }
 /**
  * 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)));
 }
 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());
 }
Example #11
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 #12
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();
 }
Example #14
0
 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 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;
 }
 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)));
 }
 /**
  * @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());
 }
Example #18
0
 /**
  * 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)));
 }
Example #19
0
 /**
  * {@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);
 }
 /**
  * @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);
 }
 /**
  * {@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
  * @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));
 }
Example #23
0
 /**
  * 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]));
 }
Example #24
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, ...)
  * @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;
     }
     if ('Symfony\\Component\\Security\\Exception\\AccessDeniedException' === $exception->getClass()) {
         $exception->setStatusCode($exception->getCode());
     }
     $templating = $this->container->get('templating');
     $template = 'FrameworkBundle:Exception:' . ($this->container->get('kernel')->isDebug() ? 'exception.php' : 'error.php');
     if (!$templating->exists($template)) {
         $this->container->get('request')->setRequestFormat('html');
     }
     $response = $templating->renderResponse($template, array('exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'embedded' => $embedded));
     $response->setStatusCode($exception->getStatusCode());
     return $response;
 }
Example #25
0
 /**
  * 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)
 {
     $opts = array();
     $params = array();
     //------------------------------
     $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();
     $message = $exception->getMessage();
     $arrAlertMessage = $this->getAlertMessage($message);
     $attrs = $request->attributes->all();
     if (isset($attrs['_route'])) {
         $route = $attrs['_route'];
     } else {
         $route = 'indefinite';
     }
     if (isset($this->app["my.opts"]) && isset($this->app["my.opts"])) {
         $opts = $this->app["my.opts"];
         $params = $this->app["my.params"];
     }
     return new Response($this->twig->render($this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('route' => $route, 'status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'parameters' => $this->ArrData2View($opts + $params))));
 }
 /**
  * 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;
 }
    /**
     * 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 exceptionAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
    {
        $this->container->get('request')->setRequestFormat($format);

        $currentContent = '';
        while (ob_get_level()) {
            $currentContent .= ob_get_clean();
        }

        if ('Symfony\Component\Security\Exception\AccessDeniedException' === $exception->getClass()) {
            $exception->setStatusCode($exception->getCode());
        }

        $template = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
        if ($this->container->get('kernel')->isDebug() && 'html' == $format) {
            $template = 'exception_full';
        }
        $template = 'FrameworkBundle:Exception:'.$template.'.twig';

        $templating = $this->container->get('templating');
        if (!$templating->exists($template)) {
            $this->container->get('request')->setRequestFormat('html');
        }

        $response = $templating->renderResponse(
            $template,
            array(
                'exception'      => $exception,
                'logger'         => $logger,
                'currentContent' => $currentContent,
            )
        );

        $response->setStatusCode($exception->getStatusCode());

        return $response;
    }
 /**
  * Determine the status code to use for the response
  *
  * @param FlattenException     $exception   A FlattenException instance
  *
  * @return integer                          An HTTP response code
  */
 protected function getStatusCode($exception)
 {
     $exceptionClass = $exception->getClass();
     $exceptionMap = $this->container->getParameter('fos_rest.exception.codes');
     return isset($exceptionMap[$exceptionClass]) ? $exceptionMap[$exceptionClass] : $exception->getStatusCode();
 }
 /**
  * {@inheritdoc}
  */
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $template = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
     $code = $exception->getStatusCode();
     return $this->container->get('templating')->renderResponse('TwigBundle:Exception:' . $template . '.html.twig', array('status_code' => $code, 'status_text' => Response::$statusTexts[$code], 'exception' => $exception, 'logger' => null, 'currentContent' => ''));
 }
 /**
  * Converts an Exception to a SoapFault Response.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \LogicException When the request query parameter "_besimple_soap_webservice" does not exist
  */
 public function exceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     if (!($webservice = $request->query->get('_besimple_soap_webservice'))) {
         throw new \LogicException(sprintf('The parameter "%s" is required in Request::$query parameter bag to generate the SoapFault.', '_besimple_soap_webservice'), null, $e);
     }
     $view = 'TwigBundle:Exception:' . ($this->container->get('kernel')->isDebug() ? 'exception' : 'error') . '.txt.twig';
     $code = $exception->getStatusCode();
     $details = $this->container->get('templating')->render($view, array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger));
     $handler = new ExceptionHandler($exception, $details);
     if ($soapFault = $request->query->get('_besimple_soap_fault')) {
         $handler->setSoapFault($soapFault);
         // Remove parameter from query because cannot be Serialized in Logger
         $request->query->remove('_besimple_soap_fault');
     }
     $server = SoapServerBuilder::createWithDefaults()->withWsdl(__DIR__ . '/../Handler/wsdl/exception.wsdl')->withWsdlCacheNone()->withHandler($handler)->build();
     ob_start();
     $server->handle('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://besim.pl/soap/exception/1.0/">' . '<soapenv:Header/>' . '<soapenv:Body>' . '<ns:exception />' . '</soapenv:Body>' . '</soapenv:Envelope>');
     return new Response(ob_get_clean());
 }