Skip to content

Commit 1c6862d

Browse files
authored
fix(symfony): use static variable to store Error (#5837)
1 parent 3fa0176 commit 1c6862d

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/Symfony/EventListener/ErrorListener.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ final class ErrorListener extends SymfonyErrorListener
4242
{
4343
use ContentNegotiationTrait;
4444
use OperationRequestInitiatorTrait;
45+
private static mixed $error;
4546

4647
public function __construct(
4748
object|array|string|null $controller,
@@ -112,10 +113,8 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re
112113
}
113114

114115
if (!$operation->getProvider()) {
115-
$data = 'jsonapi' === $format && $errorResource instanceof ConstraintViolationListAwareExceptionInterface ? $errorResource->getConstraintViolationList() : $errorResource;
116-
$dup->attributes->set('_api_error_resource', $data);
117-
$operation = $operation->withExtraProperties(['_api_error_resource' => $data])
118-
->withProvider([self::class, 'provide']);
116+
static::$error = 'jsonapi' === $format && $errorResource instanceof ConstraintViolationListAwareExceptionInterface ? $errorResource->getConstraintViolationList() : $errorResource;
117+
$operation = $operation->withProvider([self::class, 'provide']);
119118
}
120119

121120
// For our swagger Ui errors
@@ -221,13 +220,9 @@ private function getFormatOperation(?string $format): string
221220
};
222221
}
223222

224-
public static function provide(Operation $operation, array $uriVariables = [], array $context = [])
223+
public static function provide(): mixed
225224
{
226-
if ($data = ($context['request'] ?? null)?->attributes->get('_api_error_resource')) {
227-
return $data;
228-
}
229-
230-
if ($data = $operation->getExtraProperties()['_api_error_resource'] ?? null) {
225+
if ($data = static::$error) {
231226
return $data;
232227
}
233228

0 commit comments

Comments
 (0)