<?php
namespace EADPlataforma\Controller\Website;
use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use EADPlataforma\Enum\AbstractEnum;
/**
* @Route(
* schemes = {"http|https"}
* )
* @Cache(
* maxage = "0",
* smaxage = "0",
* expires = "now",
* public = false
* )
*/
class ErrorController extends Controller {
/**
* @Route(
* path = "/error",
* name = "error",
* methods = {"GET"}
* )
*/
public function errorPage(
Request $request,
FlattenException $exception,
ContainerInterface $container
) {
$debug = (int)$request->get('debug');
$eadToken = $container->getParameter('ead-token');
$errorMessage = $exception->getMessage();
$data = [
"debug" => $debug,
"trace" => $exception->getTrace(),
"errorMessage" => $errorMessage,
];
if(
$request->isXmlHttpRequest() ||
$request->getClientIp() == AbstractEnum::IP_LOCAL ||
$eadToken['sandbox']
){
return new JsonResponse(
json_encode($data),
Response::HTTP_INTERNAL_SERVER_ERROR,
[],
true
);
}
$response = new Response();
$content = "<html>
<head>
<title>error</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300&display=swap');
body{
background: linear-gradient(to right, #efefef, #fff);
}
.content{
position: absolute;
width: 300px;
z-index: 15;
top: 50%;
left: 50%;
margin: -15em 0 0 -150px;
text-align: center;
font-family: 'Lato';
}
.space{
margin-top: 1em;
}
.box-logo{
max-width: 240px;
}
.back{
text-decoration: none;
color: #333;
font-weight: 800;
}
.back:hover{
text-decoration: underline;
}
</style>
</head>
<body>
".
(
$debug ?
"<div style='border-color: black;
border: inset;
color: white;
background: #c44242;'>
<pre>{$errorMessage}</pre>
</div>" :
''
)
."<div class='content'>
<img
alt='logo'
class='box-logo'
src='https://i.imgur.com/k99dhkb.png'
/>
<div class='space'></div>
<h1>Ops...</h1>
<h3>Esse link está em manutenção. <br/> Tente acessar em alguns minutos.</h3>
<div class='space'></div>
<span><br/>
<a class='back' href='/'>
Voltar ao início
</a>
</span>
</div>
</body>
</html>";
$response->setContent($content);
$response->headers->set('Content-Type', 'text/html');
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
}