Skip to content

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

Closed
belmeopmenieuwesim wants to merge 1 commit into
Sylius:1.10from
belmeopmenieuwesim:feature/return-422-status-code-when-form-fails
Closed

Return a proper 422 HTTP status code when the form submission fails#469
belmeopmenieuwesim wants to merge 1 commit into
Sylius:1.10from
belmeopmenieuwesim:feature/return-422-status-code-when-form-fails

Conversation

@belmeopmenieuwesim

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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