Skip to content

Commit 7399fcf

Browse files
authored
feat(symfony): skip error handler (#6463)
1 parent 26d5cbb commit 7399fcf

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/Symfony/EventListener/ErrorListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re
8181
// - use api platform to handle errors (the default behavior we handle firewall errors for example but they're out of our scope)
8282

8383
// Let the error handler take this we don't handle HTML nor non-api platform requests
84-
if ('html' === $format) {
84+
if (false === ($apiOperation?->getExtraProperties()['_api_error_handler'] ?? true) || 'html' === $format) {
8585
$this->controller = 'error_controller';
8686

8787
return parent::duplicateRequest($exception, $request);

tests/Fixtures/TestBundle/ApiResource/Issue5921/ExceptionResource.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
use ApiPlatform\Metadata\Operation;
1818
use ApiPlatform\Tests\Fixtures\TestBundle\Exception\TestException;
1919

20-
#[Get(uriTemplate: 'issue5921{._format}', read: true, provider: [ExceptionResource::class, 'provide'], extraProperties: ['rfc_7807_compliant_errors' => false])]
20+
#[Get(
21+
uriTemplate: 'issue5921{._format}',
22+
read: true,
23+
provider: [ExceptionResource::class, 'provide'],
24+
extraProperties: ['_api_error_handler' => false]
25+
)]
2126
class ExceptionResource
2227
{
2328
public static function provide(Operation $operation, array $uriVariables = [], array $context = []): void

tests/Fixtures/TestBundle/Serializer/ErrorNormalizer.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace ApiPlatform\Tests\Fixtures\TestBundle\Serializer;
1515

16-
use ApiPlatform\Tests\Fixtures\TestBundle\Exception\TestException;
16+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1717
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1818

1919
final class ErrorNormalizer implements NormalizerInterface
@@ -32,20 +32,17 @@ public function normalize(mixed $object, ?string $format = null, array $context
3232

3333
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
3434
{
35-
if (\is_object($data) && $data instanceof TestException) {
36-
return true;
37-
}
38-
39-
return $this->decorated->supportsNormalization($data, $format, $context);
40-
}
41-
42-
public function hasCacheableSupportsMethod(): bool
43-
{
44-
return false;
35+
return 'json' === $format;
4536
}
4637

4738
public function getSupportedTypes(?string $format): array
4839
{
49-
return $this->decorated->getSupportedTypes($format);
40+
if ('json' === $format) {
41+
return [
42+
FlattenException::class => true,
43+
];
44+
}
45+
46+
return [];
5047
}
5148
}

tests/Fixtures/app/config/config_common.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ services:
448448
$decorated: '@.inner'
449449

450450
ApiPlatform\Tests\Fixtures\TestBundle\Serializer\ErrorNormalizer:
451-
decorates: 'api_platform.problem.normalizer.error'
452-
arguments: [ '@.inner' ]
451+
arguments: [ '@serializer.normalizer.problem' ]
452+
tags:
453+
- name: 'serializer.normalizer'
453454

454455
api_platform.http_cache.tag_collector:
455456
class: ApiPlatform\Tests\Fixtures\TestBundle\HttpCache\TagCollectorDefault

0 commit comments

Comments
 (0)