src/Subscriber/MessengerExceptionSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Subscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Symfony\Component\Messenger\Exception\HandlerFailedException;
  8. class MessengerExceptionSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @return array[]
  12.      */
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             KernelEvents::EXCEPTION => ['onKernelException', -126]
  17.         ];
  18.     }
  19.     public function onKernelException(ExceptionEvent $exceptionEvent)
  20.     {
  21.         $throwable $exceptionEvent->getThrowable();
  22.         if ($throwable instanceof HandlerFailedException) {
  23.             $exceptionEvent->setThrowable($throwable->getPrevious());
  24.         }
  25.     }
  26. }