vendor/shopware/core/Framework/Api/EventListener/ResponseExceptionListener.php line 33

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Api\EventListener;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Shopware\Core\SalesChannelRequest;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. /**
  9.  * @internal
  10.  */
  11. #[Package('core')]
  12. class ResponseExceptionListener implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(private readonly bool $debug false)
  18.     {
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             KernelEvents::EXCEPTION => [
  24.                 ['onKernelException', -1],
  25.             ],
  26.         ];
  27.     }
  28.     public function onKernelException(ExceptionEvent $event): void
  29.     {
  30.         if ($event->getRequest()->attributes->get(SalesChannelRequest::ATTRIBUTE_IS_SALES_CHANNEL_REQUEST)) {
  31.             return;
  32.         }
  33.         $exception $event->getThrowable();
  34.         $event->setResponse((new ErrorResponseFactory())->getResponseFromException($exception$this->debug));
  35.     }
  36. }