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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Api\EventListener;
  3. use Shopware\Core\SalesChannelRequest;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. /**
  8.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  9.  */
  10. class ResponseExceptionListener implements EventSubscriberInterface
  11. {
  12.     private bool $debug;
  13.     /**
  14.      * @internal
  15.      */
  16.     public function __construct(bool $debug false)
  17.     {
  18.         $this->debug $debug;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             KernelEvents::EXCEPTION => [
  24.                 ['onKernelException', -1],
  25.             ],
  26.         ];
  27.     }
  28.     /**
  29.      * @deprecated tag:v6.5.0 - reason:return-type-change - The return type will be changed to void in v6.5.0
  30.      */
  31.     public function onKernelException(ExceptionEvent $event)
  32.     {
  33.         if (
  34.             $event->getRequest()->attributes->get(SalesChannelRequest::ATTRIBUTE_IS_SALES_CHANNEL_REQUEST)
  35.             && !$event->getRequest()->attributes->has(SalesChannelRequest::ATTRIBUTE_STORE_API_PROXY)
  36.         ) {
  37.             /** @deprecated tag:v6.5.0 - it won't return the event anymore */
  38.             return $event;
  39.         }
  40.         $exception $event->getThrowable();
  41.         $event->setResponse((new ErrorResponseFactory())->getResponseFromException($exception$this->debug));
  42.         /** @deprecated tag:v6.5.0 - it won't return the event anymore */
  43.         return $event;
  44.     }
  45. }