<?php
declare(strict_types=1);
namespace App\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
class MessengerExceptionSubscriber implements EventSubscriberInterface
{
/**
* @return array[]
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => ['onKernelException', -126]
];
}
public function onKernelException(ExceptionEvent $exceptionEvent)
{
$throwable = $exceptionEvent->getThrowable();
if ($throwable instanceof HandlerFailedException) {
$exceptionEvent->setThrowable($throwable->getPrevious());
}
}
}