src/EventSubscriber/ExceptionSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  5. use Symfony\Component\HttpKernel\Exception\HttpException;
  6. use Psr\Log\LoggerInterface;
  7. class ExceptionSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var LoggerInterface;
  11.      */
  12.     private $logger;
  13.     public function __construct(       
  14.         LoggerInterface $maxxtonLogger
  15.     ) {
  16.         
  17.         $this->logger $maxxtonLogger;
  18.     }
  19.     public function onKernelException(ExceptionEvent $event)
  20.     {
  21.         // ...
  22.         $exception $event->getThrowable();
  23.         if($exception instanceof HttpException){
  24.             $this->logger->error($exception->getMessage(), [
  25.                    
  26.                 'statusCode' => $exception->getStatusCode(),
  27.             ]);            
  28.         }
  29.     }
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             'kernel.exception' => 'onKernelException',
  34.         ];
  35.     }
  36. }