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

Skip to content

Allow specifying status code for validation error when mapping query parameters using #[MapQueryParameter] #54136

Closed as not planned
@umesecke

Description

@umesecke

Description

Right now, the QueryParameterValueResolver throws a NotFoundHttpException if the parameter could not be mapped successfully because of filter settings or providing a wrong value for a backed enum.

We would like to return "400 Bad Request" responses instead. Ideally this would be a parameter in the MapQueryParameter attribute same as for the MapQueryString or MapRequestPayload attributes where this already exists in $validationFailedStatusCode = Response::HTTP_NOT_FOUND.

Example

Before:

#[Route("/hello")]
public function action(
    #[MapQueryParameter] MyBackedEnum $option,
): Response
{
    // ...
}

After:

#[Route("/hello")]
public function action(
    #[MapQueryParameter(validationFailedStatusCode: Response::HTTP_BAD_REQUEST)] MyBackedEnum $option,
): 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