src/Controller/Website/ErrorController.php line 37

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  3. use Psr\Container\ContainerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\ErrorHandler\Exception\FlattenException;
  11. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  12. use EADPlataforma\Enum\AbstractEnum;
  13. /**
  14.  * @Route(
  15.  *      schemes         = {"http|https"}
  16.  * )
  17.  * @Cache(
  18.  *      maxage          = "0",
  19.  *      smaxage         = "0",
  20.  *      expires         = "now",
  21.  *      public          = false
  22.  * )
  23.  */
  24. class ErrorController extends Controller {
  25.     /**
  26.      * @Route(
  27.      *      path          = "/error",
  28.      *      name          = "error",
  29.      *      methods       = {"GET"}
  30.      * )
  31.      */
  32.     public function errorPage(
  33.         Request $request
  34.         FlattenException $exception
  35.         ContainerInterface $container
  36.     ) {
  37.         
  38.         $debug = (int)$request->get('debug');
  39.         $eadToken $container->getParameter('ead-token');
  40.         $errorMessage $exception->getMessage();
  41.         $data = [
  42.             "debug" => $debug,
  43.             "trace" => $exception->getTrace(),
  44.             "errorMessage" => $errorMessage,
  45.         ];
  46.         if(
  47.             $request->isXmlHttpRequest() ||
  48.             $request->getClientIp() == AbstractEnum::IP_LOCAL ||
  49.             $eadToken['sandbox'
  50.         ){
  51.             return new JsonResponse(
  52.                 json_encode($data), 
  53.                 Response::HTTP_INTERNAL_SERVER_ERROR
  54.                 [], 
  55.                 true
  56.             );
  57.         }
  58.         $response = new Response();
  59.         $content "<html>
  60.             <head>
  61.                 <title>error</title>
  62.                 <style>
  63.                     @import url('https://fonts.googleapis.com/css2?family=Lato:wght@300&display=swap');
  64.                     body{
  65.                         background: linear-gradient(to right, #efefef, #fff);
  66.                     }
  67.                     .content{
  68.                         position: absolute;
  69.                         width: 300px;
  70.                         z-index: 15;
  71.                         top: 50%;
  72.                         left: 50%;
  73.                         margin: -15em 0 0 -150px;
  74.                         text-align: center;
  75.                         font-family: 'Lato';
  76.                     }
  77.                     .space{
  78.                         margin-top: 1em;
  79.                     }
  80.                     .box-logo{
  81.                         max-width: 240px;
  82.                     }
  83.                     .back{
  84.                         text-decoration: none;
  85.                         color: #333;
  86.                         font-weight: 800;
  87.                     }
  88.                     .back:hover{
  89.                         text-decoration: underline;
  90.                     }
  91.                 </style>
  92.             </head>
  93.             <body>
  94.                 ".
  95.                 (
  96.                     $debug 
  97.                     "<div style='border-color: black;
  98.                             border: inset;
  99.                             color: white;
  100.                             background: #c44242;'>
  101.                         <pre>{$errorMessage}</pre>
  102.                     </div>" 
  103.                     ''
  104.                 )
  105.                 ."<div class='content'>
  106.                     <img 
  107.                         alt='logo'
  108.                         class='box-logo'
  109.                         src='https://i.imgur.com/k99dhkb.png'
  110.                     />
  111.                     <div class='space'></div>
  112.                     <h1>Ops...</h1>
  113.                     <h3>Esse link está em manutenção. <br/> Tente acessar em alguns minutos.</h3>
  114.                     <div class='space'></div>
  115.                     <span><br/>
  116.                         <a class='back' href='/'>
  117.                             Voltar ao início
  118.                         </a>
  119.                     </span>
  120.                 </div>
  121.             </body>
  122.         </html>";
  123.         $response->setContent($content);
  124.         $response->headers->set('Content-Type''text/html');
  125.         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
  126.         return $response;
  127.     }
  128. }