You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.0KB

  1. <?php
  2. namespace Lc\SovBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\Mailer\MailerInterface;
  5. use Throwable;
  6. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  7. use Symfony\Component\Mime\Email;
  8. class ErrorController extends AbstractController
  9. {
  10. public function show($exception, DebugLoggerInterface $logger = null, MailerInterface $mailer)
  11. {
  12. //Si != de 404 on envoit un mail de debug
  13. if ($exception->getStatusCode() != 404) {
  14. $mailDebug = $this->getParameter('app.mail_debug');
  15. if ($mailDebug) {
  16. $message = "Code : " . $exception->getStatusCode() . "<br>";
  17. $message .= "Message : " . $exception->getMessage() . "<br>";
  18. $message .= "File : " . $exception->getFile() . "<br>";
  19. $message .= "Line : " . $exception->getLine() . "<br><br>";
  20. $message .= "Trace : <br>" . str_replace("\n", "<br>", $exception->getTraceAsString());
  21. $siteName = $this->getParameter('app.site_name');
  22. $email = (new Email())
  23. ->from('nepasrepondre@laclic.fr')
  24. ->to($mailDebug)
  25. ->subject(
  26. '[' . $siteName . '] [ERREUR ' . $exception->getStatusCode() . '] ' . $exception->getMessage(
  27. ) . ''
  28. )
  29. ->text(strip_tags($message))
  30. ->html($message);
  31. $mailer->send($email);
  32. }
  33. }
  34. if (str_contains($this->getRequestStack()->getCurrentRequest(), "/admin")) {
  35. return $this->render('@LcSov/exception/error.html.twig', [
  36. "code" => $exception->getStatusCode(),
  37. "message" => $exception->getMessage()
  38. ]);
  39. } else {
  40. return $this->render('bundles/TwigBundle/Exception/error.html.twig', [
  41. "code" => $exception->getStatusCode(),
  42. "message" => $exception->getMessage()
  43. ]);
  44. }
  45. }
  46. }