Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Allow customising HTTP status code on validation error of #[MapRequestPayload] objects #50992

Copy link
Copy link
Closed
@siketyan

Description

@siketyan
Issue body actions

Description

#[MapRequestPayload] attribute, introduced in Symfony 6.3, is an awesome feature for APIs that use JSON for requests. The attribute works with Serializer and Validator components, and returns 422 Unprocessable Entity status code on Validator returned any violation(s). However, in API development, sometimes we want 400 Bad Request instead of 422. So it would be great if we can customise the status code that MapRequestPayload returns on validation error.

Example

Option 1. Use attribute to customise for each endpoint

#[Route('/pets', methods: ['POST'])]
public function createPet(
    #[MapRequestPayload(statusOnError: Response::HTTP_BAD_REQUEST) PetDto $pet,
): Response;

Option 2. Use config to customise globally

framework:
    map_request_payload:
        default_status_code_on_error: 400

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.