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

Open in your IDE?
  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.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  10.  */
  11. #[Package('core')]
  12. class ResponseExceptionListener implements EventSubscriberInterface
  13. {
  14.     private bool $debug;
  15.     /**
  16.      * @internal
  17.      */
  18.     public function __construct(bool $debug false)
  19.     {
  20.         $this->debug $debug;
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             KernelEvents::EXCEPTION => [
  26.                 ['onKernelException', -1],
  27.             ],
  28.         ];
  29.     }
  30.     /**
  31.      * @deprecated tag:v6.5.0 - reason:return-type-change - The return type will be changed to void in v6.5.0
  32.      */
  33.     public function onKernelException(ExceptionEvent $event)
  34.     {
  35.         if (
  36.             $event->getRequest()->attributes->get(SalesChannelRequest::ATTRIBUTE_IS_SALES_CHANNEL_REQUEST)
  37.             && !$event->getRequest()->attributes->has(SalesChannelRequest::ATTRIBUTE_STORE_API_PROXY)
  38.         ) {
  39.             /** @deprecated tag:v6.5.0 - it won't return the event anymore */
  40.             return $event;
  41.         }
  42.         $exception $event->getThrowable();
  43.         $event->setResponse((new ErrorResponseFactory())->getResponseFromException($exception$this->debug));
  44.         /** @deprecated tag:v6.5.0 - it won't return the event anymore */
  45.         return $event;
  46.     }
  47. }