選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

63 行
2.5KB

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