|
24 | 24 | use ApiPlatform\Metadata\Exception\OperationNotFoundException;
|
25 | 25 | use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
|
26 | 26 | use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException;
|
| 27 | +use ApiPlatform\Metadata\Exception\RuntimeException; |
27 | 28 | use ApiPlatform\Metadata\HeaderParameterInterface;
|
28 | 29 | use ApiPlatform\Metadata\HttpOperation;
|
29 | 30 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
|
55 | 56 | use ApiPlatform\OpenApi\Serializer\NormalizeOperationNameTrait;
|
56 | 57 | use ApiPlatform\State\Pagination\PaginationOptions;
|
57 | 58 | use Psr\Container\ContainerInterface;
|
58 |
| -use Psr\Log\LoggerInterface; |
59 | 59 | use Symfony\Component\PropertyInfo\Type;
|
60 | 60 | use Symfony\Component\Routing\RouteCollection;
|
61 | 61 | use Symfony\Component\Routing\RouterInterface;
|
@@ -93,7 +93,6 @@ public function __construct(
|
93 | 93 | ?Options $openApiOptions = null,
|
94 | 94 | ?PaginationOptions $paginationOptions = null,
|
95 | 95 | private readonly ?RouterInterface $router = null,
|
96 |
| - private readonly ?LoggerInterface $logger = null |
97 | 96 | ) {
|
98 | 97 | $this->filterLocator = $filterLocator;
|
99 | 98 | $this->openApiOptions = $openApiOptions ?: new Options('API Platform');
|
@@ -883,39 +882,33 @@ private function addOperationErrors(Operation $operation, array $errors, array $
|
883 | 882 | $existingResponses = null;
|
884 | 883 | foreach ($errors as $error) {
|
885 | 884 | if (!is_a($error, ProblemExceptionInterface::class, true)) {
|
886 |
| - $this->logger?->warning(\sprintf('The error class "%s" does not implement "%s". Did you forget a use statement?', $error, ProblemExceptionInterface::class)); |
| 885 | + throw new RuntimeException(\sprintf('The error class "%s" does not implement "%s". Did you forget a use statement?', $error, ProblemExceptionInterface::class)); |
887 | 886 | }
|
888 | 887 |
|
889 | 888 | $status = null;
|
890 | 889 | $description = null;
|
| 890 | + |
891 | 891 | try {
|
892 |
| - /** @var ProblemExceptionInterface */ |
893 |
| - $exception = (new \ReflectionClass($error))->newInstanceWithoutConstructor(); |
| 892 | + /** @var ProblemExceptionInterface $exception */ |
| 893 | + $exception = new $error(); |
894 | 894 | $status = $exception->getStatus();
|
895 | 895 | $description = $exception->getTitle();
|
896 |
| - } catch (\ReflectionException) { |
| 896 | + } catch (\TypeError) { |
897 | 897 | }
|
898 | 898 |
|
899 | 899 | try {
|
900 | 900 | $errorOperation = $this->resourceMetadataFactory->create($error)->getOperation();
|
901 | 901 | if (!is_a($errorOperation, Error::class)) {
|
902 |
| - $this->logger?->warning(\sprintf('The error class %s is not an ErrorResource', $error)); |
903 |
| - continue; |
| 902 | + throw new RuntimeException(\sprintf('The error class %s is not an ErrorResource', $error)); |
904 | 903 | }
|
905 |
| - /* @var Error $errorOperation */ |
906 |
| - $status ??= $errorOperation->getStatus(); |
907 |
| - $description ??= $errorOperation->getDescription(); |
908 | 904 | } catch (ResourceClassNotFoundException|OperationNotFoundException) {
|
909 |
| - $this->logger?->warning(\sprintf('The error class %s is not an ErrorResource', $error)); |
910 |
| - continue; |
| 905 | + $errorOperation = null; |
911 | 906 | }
|
| 907 | + $status ??= $errorOperation?->getStatus(); |
| 908 | + $description ??= $errorOperation?->getDescription(); |
912 | 909 |
|
913 | 910 | if (!$status) {
|
914 |
| - $this->logger?->error(\sprintf( |
915 |
| - 'The error class %s has no status defined, please either implement ProblemExceptionInterface, or make it an ErrorResource with a status', |
916 |
| - $error |
917 |
| - )); |
918 |
| - continue; |
| 911 | + throw new RuntimeException(\sprintf('The error class %s has no status defined, please either implement ProblemExceptionInterface, or make it an ErrorResource with a status', $error)); |
919 | 912 | }
|
920 | 913 |
|
921 | 914 | $operationErrorSchemas = [];
|
|
0 commit comments