Skip to content

Commit 00638aa

Browse files
committed
fix: error formats
todo: test
1 parent b179302 commit 00638aa

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/Symfony/EventListener/ErrorListener.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/*
43
* This file is part of the API Platform project.
54
*
@@ -68,8 +67,9 @@ public function __construct(
6867
protected function duplicateRequest(\Throwable $exception, Request $request): Request
6968
{
7069
$format = $this->getRequestFormat($request, $this->errorFormats, false);
71-
// Because ErrorFormatGuesser is buggy in some cases
72-
$request->setRequestFormat($format);
70+
// Reset the request format as it may be that the original request format negotiation won't have the same result
71+
// when an error occurs
72+
$request->setRequestFormat(null);
7373
$apiOperation = $this->initializeOperation($request);
7474

7575
// TODO: add configuration flag to:
@@ -121,7 +121,6 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re
121121
$dup->attributes->set('_api_original_uri_variables', $request->attributes->get('_api_uri_variables'));
122122
$dup->attributes->set('_api_requested_operation', $request->attributes->get('_api_requested_operation'));
123123
$dup->attributes->set('_api_platform_disable_listeners', true);
124-
125124
return $dup;
126125
}
127126

src/Symfony/Routing/ApiLoader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ public function load(mixed $data, ?string $type = null): RouteCollection
9090
$path,
9191
[
9292
'_controller' => $controller ?? 'api_platform.action.placeholder',
93-
'_format' => null,
9493
'_stateless' => $operation->getStateless(),
9594
'_api_resource_class' => $resourceClass,
9695
'_api_operation_name' => $operationName,
97-
] + ($operation->getDefaults() ?? []),
96+
] + ($operation->getDefaults() ?? []) + ['_format' => null],
9897
$operation->getRequirements() ?? [],
9998
$operation->getOptions() ?? [],
10099
$operation->getHost() ?? '',

0 commit comments

Comments
 (0)