• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

0 of 2 new or added lines in 2 files covered. (0.0%)

11040 existing lines in 370 files now uncovered.

0 of 48303 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\GraphQl\Serializer\Exception;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use ApiPlatform\Validator\Exception\ConstraintViolationListAwareExceptionInterface;
18
use GraphQL\Error\Error;
19
use GraphQL\Error\FormattedError;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
22

23
/**
24
 * Normalize validation exceptions.
25
 *
26
 * @author Mahmood Bazdar <mahmood@bazdar.me>
27
 * @author Alan Poulain <contact@alanpoulain.eu>
28
 */
29
final class ValidationExceptionNormalizer implements NormalizerInterface
30
{
31
    public function __construct(private readonly array $exceptionToStatus = [])
32
    {
UNCOV
33
    }
×
34

35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function normalize(mixed $object, ?string $format = null, array $context = []): array
39
    {
40
        $validationException = $object->getPrevious();
×
41
        if (!$validationException instanceof ConstraintViolationListAwareExceptionInterface) {
×
42
            throw new RuntimeException(\sprintf('Object is not a "%s".', ConstraintViolationListAwareExceptionInterface::class));
×
43
        }
44

45
        $error = FormattedError::createFromException($object);
×
46
        $error['message'] = $validationException->getMessage();
×
47

48
        $exceptionClass = $validationException::class;
×
49
        $statusCode = Response::HTTP_UNPROCESSABLE_ENTITY;
×
50

51
        foreach ($this->exceptionToStatus as $class => $status) {
×
52
            if (is_a($exceptionClass, $class, true)) {
×
53
                $statusCode = $status;
×
54

55
                break;
×
56
            }
57
        }
58
        $error['extensions']['status'] = $statusCode;
×
59
        // graphql-php < 15
60
        if (\defined(Error::class.'::CATEGORY_INTERNAL')) {
×
61
            $error['extensions']['category'] = 'user';
×
62
        }
63
        $error['extensions']['violations'] = [];
×
64

65
        foreach ($validationException->getConstraintViolationList() as $violation) {
×
66
            $error['extensions']['violations'][] = [
×
67
                'path' => $violation->getPropertyPath(),
×
68
                'message' => $violation->getMessage(),
×
69
            ];
×
70
        }
71

72
        return $error;
×
73
    }
74

75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
79
    {
UNCOV
80
        return $data instanceof Error && ($data->getPrevious() instanceof ConstraintViolationListAwareExceptionInterface);
×
81
    }
82

83
    public function getSupportedTypes($format): array
84
    {
UNCOV
85
        return [
×
UNCOV
86
            Error::class => false,
×
UNCOV
87
        ];
×
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc