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

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. class ResponseExceptionListener implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var bool
  11.      */
  12.     private $debug;
  13.     public function __construct($debug false)
  14.     {
  15.         $this->debug $debug;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             KernelEvents::EXCEPTION => [
  21.                 ['onKernelException', -1],
  22.             ],
  23.         ];
  24.     }
  25.     public function onKernelException(ExceptionEvent $event)
  26.     {
  27.         if (
  28.             $event->getRequest()->attributes->get(SalesChannelRequest::ATTRIBUTE_IS_SALES_CHANNEL_REQUEST)
  29.             && !$event->getRequest()->attributes->has(SalesChannelRequest::ATTRIBUTE_STORE_API_PROXY)
  30.         ) {
  31.             return $event;
  32.         }
  33.         $exception $event->getThrowable();
  34.         $event->setResponse((new ErrorResponseFactory())->getResponseFromException($exception$this->debug));
  35.         return $event;
  36.     }
  37. }