getCode() public method

public getCode ( )
コード例 #1
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());
 }
コード例 #2
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;
 }
コード例 #3
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(), '/api') !== false) {
             $dataArray = array('error' => array('message' => $exception->getMessage(), 'code' => $exception->getCode()));
             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'])));
     }
 }