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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
umesecke opened this issue Mar 2, 2024 · 1 comment

Comments

@umesecke
Copy link

umesecke commented Mar 2, 2024

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
{
    // ...
}
@umesecke
Copy link
Author

umesecke commented Mar 2, 2024

Nevermind 🤦

#53209

Simpsons Symfony already did it!

@umesecke umesecke closed this as completed Mar 2, 2024
@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants