|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Lc\SovBundle\Controller; |
|
|
namespace Lc\SovBundle\Controller; |
|
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
|
use Symfony\Component\Mailer\MailerInterface; |
|
|
use Throwable; |
|
|
use Throwable; |
|
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; |
|
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; |
|
|
|
|
|
use Symfony\Component\Mime\Email; |
|
|
|
|
|
|
|
|
class ErrorController extends AbstractController |
|
|
class ErrorController extends AbstractController |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
public function show(Throwable $exception, DebugLoggerInterface $logger = null) |
|
|
|
|
|
|
|
|
public function show($exception, DebugLoggerInterface $logger = null, MailerInterface $mailer) |
|
|
{ |
|
|
{ |
|
|
|
|
|
//Si != de 404 on envoit un mail de debug |
|
|
|
|
|
if ($exception->getStatusCode() != 404) { |
|
|
|
|
|
$mailDebug = $this->getParameter('app.mail_debug'); |
|
|
|
|
|
if ($mailDebug) { |
|
|
|
|
|
$message = "Code : " . $exception->getStatusCode() . "<br>"; |
|
|
|
|
|
$message .= "Message : " . $exception->getMessage() . "<br>"; |
|
|
|
|
|
$message .= "File : " . $exception->getFile() . "<br>"; |
|
|
|
|
|
$message .= "Line : " . $exception->getLine() . "<br><br>"; |
|
|
|
|
|
$message .= "Trace : <br>" . str_replace("\n", "<br>", $exception->getTraceAsString()); |
|
|
|
|
|
$siteName = $this->getParameter('app.site_name'); |
|
|
|
|
|
$email = (new Email()) |
|
|
|
|
|
->from('nepasrepondre@laclic.fr') |
|
|
|
|
|
->to($mailDebug) |
|
|
|
|
|
->subject( |
|
|
|
|
|
'[' . $siteName . '] [ERREUR ' . $exception->getStatusCode() . '] ' . $exception->getMessage( |
|
|
|
|
|
) . '' |
|
|
|
|
|
) |
|
|
|
|
|
->text(strip_tags($message)) |
|
|
|
|
|
->html($message); |
|
|
|
|
|
|
|
|
|
|
|
$mailer->send($email); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
if (str_contains($this->getRequestStack()->getCurrentRequest(), "/admin")) { |
|
|
if (str_contains($this->getRequestStack()->getCurrentRequest(), "/admin")) { |
|
|
return $this->render('@LcSov/exception/error.html.twig', [ |
|
|
return $this->render('@LcSov/exception/error.html.twig', [ |
|
|
"code" => $exception->getCode(), |
|
|
|
|
|
|
|
|
"code" => $exception->getStatusCode(), |
|
|
"message" => $exception->getMessage() |
|
|
"message" => $exception->getMessage() |
|
|
]); |
|
|
]); |
|
|
} else { |
|
|
} else { |
|
|
return $this->render('bundles/TwigBundle/Exception/error.html.twig', [ |
|
|
return $this->render('bundles/TwigBundle/Exception/error.html.twig', [ |
|
|
"code" => $exception->getCode(), |
|
|
|
|
|
|
|
|
"code" => $exception->getStatusCode(), |
|
|
"message" => $exception->getMessage() |
|
|
"message" => $exception->getMessage() |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |