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

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.     /**
  14.      * @internal
  15.      */
  16.     public function __construct($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.     public function onKernelException(ExceptionEvent $event)
  29.     {
  30.         if (
  31.             $event->getRequest()->attributes->get(SalesChannelRequest::ATTRIBUTE_IS_SALES_CHANNEL_REQUEST)
  32.             && !$event->getRequest()->attributes->has(SalesChannelRequest::ATTRIBUTE_STORE_API_PROXY)
  33.         ) {
  34.             return $event;
  35.         }
  36.         $exception $event->getThrowable();
  37.         $event->setResponse((new ErrorResponseFactory())->getResponseFromException($exception$this->debug));
  38.         return $event;
  39.     }
  40. }