From 9ab7af5306bd9c52c579b47a7a61d94aa7519d4c Mon Sep 17 00:00:00 2001 From: soyuka Date: Tue, 19 Sep 2023 15:02:12 +0200 Subject: [PATCH] fix(symfony): use static variable to store Error --- src/Symfony/EventListener/ErrorListener.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Symfony/EventListener/ErrorListener.php b/src/Symfony/EventListener/ErrorListener.php index b7f94dc1d2a..dad2a70f394 100644 --- a/src/Symfony/EventListener/ErrorListener.php +++ b/src/Symfony/EventListener/ErrorListener.php @@ -42,6 +42,7 @@ final class ErrorListener extends SymfonyErrorListener { use ContentNegotiationTrait; use OperationRequestInitiatorTrait; + private static mixed $error; public function __construct( object|array|string|null $controller, @@ -112,10 +113,8 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re } if (!$operation->getProvider()) { - $data = 'jsonapi' === $format && $errorResource instanceof ConstraintViolationListAwareExceptionInterface ? $errorResource->getConstraintViolationList() : $errorResource; - $dup->attributes->set('_api_error_resource', $data); - $operation = $operation->withExtraProperties(['_api_error_resource' => $data]) - ->withProvider([self::class, 'provide']); + static::$error = 'jsonapi' === $format && $errorResource instanceof ConstraintViolationListAwareExceptionInterface ? $errorResource->getConstraintViolationList() : $errorResource; + $operation = $operation->withProvider([self::class, 'provide']); } // For our swagger Ui errors @@ -221,13 +220,9 @@ private function getFormatOperation(?string $format): string }; } - public static function provide(Operation $operation, array $uriVariables = [], array $context = []) + public static function provide(): mixed { - if ($data = ($context['request'] ?? null)?->attributes->get('_api_error_resource')) { - return $data; - } - - if ($data = $operation->getExtraProperties()['_api_error_resource'] ?? null) { + if ($data = static::$error) { return $data; }