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