Skip to content

RequestPayloadValueResolver should catch invalid values of backed enums #58208

Closed as not planned
@stollr

Description

@stollr

Description

If a controller argument is attributed with MapQueryString and the class contains a property, which is a backed enum, the BackedEnumNormalizer is used to denormalize the value. If a user submits an invalid value for the enum, a ValueError is catched and an Symfony\Component\Serializer\Exception\InvalidArgumentException is rethrown.

But this exception is never catched and thus resulting in a 500 internal server error response.

I suggest catching this exception in the RequestPayloadValueResolver and throw an HttpException
with a 422 or 400 status code (or with the validationFailedStatusCode defined in the attribute), because this is a client error.

What do you think?

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions