core icon indicating copy to clipboard operation
core copied to clipboard

Invalid submitted json is reported as server error

Open rimas-kudelis opened this issue 4 years ago • 3 comments

API Platform version(s) affected: 2.6.8

Description
When invalid JSON is being submitted to a POST endpoint, a 500 status code is being returned even though invalid input is a user error, not that of the server. A proper status code for this case would be 400, I think.

How to reproduce
Submit intentionally broken JSON body to a POST endpoint, e.g., without a closing brace.

For a quick demo:

  1. Open https://demo.sylius.com/api/v2/.
  2. Find the group of requests named "Customer".
  3. Expand the POST endpoint
  4. paste the following body and submit the request:
    {
      "firstName": "John",
      "lastName": "Doe",
      "email": "[email protected]",
      "password": "Password",
      "subscribedToNewsletter": true
    
  5. Note that you get a 500 server error. If you add the missing brace, you'll get an expected response code (204 or 422).

rimas-kudelis avatar Apr 05 '22 13:04 rimas-kudelis

It's actually weird that default configuration doesn't come with:

exception_to_status:
    Symfony\Component\Serializer\Exception\ExceptionInterface: 400

gaetan-petit avatar Oct 24 '22 12:10 gaetan-petit

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 24 '22 06:12 stale[bot]

Has it really been fixed though?

rimas-kudelis avatar Dec 31 '22 14:12 rimas-kudelis