<?php
declare(strict_types=1);
namespace App\Infrastructure\Shared\Symfony\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Messenger\Exception\ValidationFailedException;
class ExceptionSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return [
KernelEvents::EXCEPTION => [
['processException'],
],
];
}
public function processException(ExceptionEvent $event)
{
$throwable = $event->getThrowable();
if ($throwable instanceof ValidationFailedException) {
dump($throwable->getViolations());
exit;
}
}
}