8000 [HttpKernel] Customise error code on validation error occurred in #[MapRequestPayload] by siketyan · Pull Request #50993 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Customise error code on validation error occurred in #[MapRequestPayload] #50993

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

Conversation

siketyan
Copy link
Contributor
Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #50992
License MIT
Doc PR TBD

This pull request proposes to allow customising HTTP status code that will be returned from #[MapRequestPayload] value resolver.

Users can customise by two methods:

  1. Use the argument in the attribute

    #[MapRequestPayload(statusCodeOnError: Response::HTTP_BAD_REQUEST)]
  2. Use framework configuration for global

    framework:
        map_request_payload:
            status_code_on_error: 400

siketyan added 4 commits July 16, 2023 22:09
Signed-off-by: Natsuki Ikeguchi <me@s6n.jp>
Signed-off-by: Natsuki Ikeguchi <me@s6n.jp>
Signed-off-by: Natsuki Ikeguchi <me@s6n.jp>
@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@siketyan siketyan marked this pull request as ready for review July 16, 2023 13:38
@carsonbot carsonbot added this to the 6.4 milestone Jul 16, 2023
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

->arrayNode('map_request_payload')
->addDefaultsIfNotSet()
->children()
->scalarNode('status_code_on_error')
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a usecase that requires a different default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As described in #50992, sometimes we want use 400 instead of 422 in application-global. So this configuration node supports to change the HTTP status code on error globally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, this is actually dupe of #50767, so I'll close this pull request now.

@siketyan siketyan closed this Jul 16, 2023
@siketyan siketyan deleted the feat/maprequestpayload-customise-status-code branch July 16, 2023 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HttpKernel] Allow customising HTTP status code on validation error of #[MapRequestPayload] objects
3 participants
0