<?php
namespace App\EventSubscriber;
use App\Exception\AccountDeletedException;
use Junker\JSendResponse\JSendFailResponse;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class AccountDeletedExceptionEventSubscriber implements EventSubscriberInterface
{
public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();
if (!($exception instanceof AccountDeletedException)) {
return;
}
$event->setResponse(
new JSendFailResponse('This account has been deleted.', JSendFailResponse::HTTP_FORBIDDEN)
);
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => 'onKernelException',
];
}
}