I’m trying to issue a 404 from a KernelEvents::REQUEST event, but it’s resulting in the following error:
Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/vendor/symfony/http-foundation/HeaderBag.php on line 162
Here’s my class
<?php namespace Drupalmy_moduleEventSubscriber; use SymfonyComponentEventDispatcherEventSubscriberInterface; use SymfonyComponentHttpFoundationRequest; use SymfonyComponentHttpKernelEventGetResponseEvent; use SymfonyComponentHttpKernelExceptionNotFoundHttpException; use SymfonyComponentHttpKernelKernelEvents; class MyClass implements EventSubscriberInterface { /** * {@inheritdoc} */ static function getSubscribedEvents() { $events[KernelEvents::REQUEST][] = ['my404Check']; return $events; } public function my404Check(GetResponseEvent $event) { // Do some logic here to check if it should be a 404. throw new NotFoundHttpException(); } }
I’m guessing I can’t throw exceptions here, but can’t see any other documentation on how to issue the 404.
Sponsored by SupremePR