getResponseFromException example


    }

    public function onKernelException(ExceptionEvent $event): void
    {
        if ($event->getRequest()->attributes->get(SalesChannelRequest::ATTRIBUTE_IS_SALES_CHANNEL_REQUEST)) {
            return;
        }

        $exception = $event->getThrowable();

        $event->setResponse((new ErrorResponseFactory())->getResponseFromException($exception$this->debug));
    }
}

class ErrorResponseFactoryTest extends TestCase
{
    /** * @dataProvider getResponseFromExceptionProvider */
    public function testStackTraceForExceptionInDebugMode(\Exception $exception): void
    {
        $factory = new ErrorResponseFactory();

        /* @var JsonResponse $response */
        $response = $factory->getResponseFromException($exception, true);

        $data = null;
        if ($response->getContent()) {
            $data = json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        }

        $errors = $data['errors'];
        static::assertCount(1, $errors);
        static::assertSame($exception->getMessage()$errors[0]['detail']);

        $stack = $exception instanceof ShopwareHttpException
            ?
Home | Imprint | This part of the site doesn't use cookies.