forked from wallabag/wallabag
Convert 403 errors to 404 errors
This commit is contained in:
29
src/Event/Subscriber/AccessDeniedToNotFoundSubscriber.php
Normal file
29
src/Event/Subscriber/AccessDeniedToNotFoundSubscriber.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Event\Subscriber;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
class AccessDeniedToNotFoundSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
KernelEvents::EXCEPTION => 'onKernelException',
|
||||
];
|
||||
}
|
||||
|
||||
public function onKernelException(ExceptionEvent $event): void
|
||||
{
|
||||
$exception = $event->getThrowable();
|
||||
|
||||
if ($exception instanceof AccessDeniedHttpException) {
|
||||
$notFoundException = new NotFoundHttpException('', $exception);
|
||||
$event->setThrowable($notFoundException);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user