Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[RFC] Add a ValidationException #60234

Open
@lyrixx

Description

@lyrixx

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions