Skip to content
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

Return a proper 422 HTTP status code when the form submission fails #469

Conversation

belmeopmenieuwesim
Copy link
Contributor

I noticed that the resource controller does not set the 422 http status code when a form submission fails. It is a good practice to do so. Also this will bring support for Symfony UX Turbo, which requires the status code to be set to 422 upon form failure.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
License MIT

This also brings support for Symfony UX Turbo
@belmeopmenieuwesim belmeopmenieuwesim requested a review from a team as a code owner July 27, 2022 20:43
$parameters[$k] = $v->createView();

if (200 === $response->getStatusCode() && $v->isSubmitted() && !$v->isValid()) {
$response->setStatusCode(422);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using Resonse::UNPROCESSABLE_ENTITY?

does the code you wrote come from Symfony itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i just copied it directly from Symfony's AbstractController.

@belmeopmenieuwesim
Copy link
Contributor Author

Please look at this..

lchrusciel added a commit that referenced this pull request Oct 18, 2022
…im, Zales0123)

This PR was merged into the 1.10 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | replaces #469
| License         | MIT

I\'ve taken over the #469 PR, added some tests and clean up the code. Thank you, @belmeopmenieuwesim, for the contribution 🖖 

Commits
-------

1127c3d Return a proper 422 HTTP status code when the form submission fails
cf06855 Test validation error code
2f3dfc2 Remove additional function for rendering the form from ControllerTrait
@Zales0123
Copy link
Member

Merged in #488 🖖 Thank you!

@Zales0123 Zales0123 closed this Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants