Skip to content

Commit 07deb11

Browse files
committed
fix(symfony): use static variable to store Error
1 parent 3fa0176 commit 07deb11

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/Symfony/EventListener/ErrorListener.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
final class ErrorListener extends SymfonyErrorListener
4242
{
43+
private static mixed $error;
44+
4345
use ContentNegotiationTrait;
4446
use OperationRequestInitiatorTrait;
4547

@@ -112,10 +114,8 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re
112114
}
113115

114116
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']);
117+
static::$error = 'jsonapi' === $format && $errorResource instanceof ConstraintViolationListAwareExceptionInterface ? $errorResource->getConstraintViolationList() : $errorResource;
118+
$operation = $operation->withProvider([self::class, 'provide']);
119119
}
120120

121121
// For our swagger Ui errors
@@ -221,13 +221,9 @@ private function getFormatOperation(?string $format): string
221221
};
222222
}
223223

224-
public static function provide(Operation $operation, array $uriVariables = [], array $context = [])
224+
public static function provide(): mixed
225225
{
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) {
226+
if ($data = static::$error) {
231227
return $data;
232228
}
233229

0 commit comments

Comments
 (0)