custom/plugins/FroshDevelopmentHelper/src/Subscriber/DisableStorefrontErrorHandling.php line 24

  1. <?php
  2. namespace Frosh\DevelopmentHelper\Subscriber;
  3. use Shopware\Core\PlatformRequest;
  4. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. class DisableStorefrontErrorHandling implements EventSubscriberInterface
  9. {
  10.     public function __construct(private readonly ContainerBagInterface $containerBag)
  11.     {
  12.     }
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             KernelEvents::EXCEPTION => ['disableFrontendErrorHandling', -95]
  17.         ];
  18.     }
  19.     public function disableFrontendErrorHandling(ExceptionEvent $event): void
  20.     {
  21.         //if we are in dev mode, we will see exceptions
  22.         if ($this->containerBag->all()['kernel.debug']) {
  23.             return;
  24.         }
  25.         if ($event->getRequest()->attributes->has(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT)) {
  26.             $event->stopPropagation();
  27.         }
  28.     }
  29. }