Open
Description
Description
We already have a Support in the normalizer to Serialize a ConstraintViolationList
.
So I would be nice to be able to throw an exception that contains an instance of ConstraintViolationList
In the we have this line (https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php#L154)
throw HttpException::fromStatusCode($validationFailedCode, implode("\n", array_map(static fn ($e) => $e->getMessage(), iterator_to_array($violations))), new ValidationFailedException($payload, $violations));
Side node: the massage (implode(...)) is not used in the response (and this is not easily readable, but that's another topic)
So I would like to propose a new exception that does everything for us.
WDYT?
Example
This would allow to simplify this code:
$violations = ConstraintViolationList::createFromMessage('Shipper not found');
$previous = new ValidationFailedException($setLivraisonDto, $violations);
throw new HttpException(422, 'validation exception', $previous);