vendor/shopware/platform/src/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'],
  22.             ],
  23.         ];
  24.     }
  25.     public function onKernelException(ExceptionEvent $event)
  26.     {
  27.         if ($event->getRequest()->attributes->get(SalesChannelRequest::ATTRIBUTE_IS_SALES_CHANNEL_REQUEST)) {
  28.             return $event;
  29.         }
  30.         $exception $event->getThrowable();
  31.         $event->setResponse((new ErrorResponseFactory())->getResponseFromException($exception$this->debug));
  32.         return $event;
  33.     }
  34. }