core
core copied to clipboard
Invalid submitted json is reported as server error
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:
- Open https://demo.sylius.com/api/v2/.
- Find the group of requests named "Customer".
- Expand the POST endpoint
- paste the following body and submit the request:
{ "firstName": "John", "lastName": "Doe", "email": "[email protected]", "password": "Password", "subscribedToNewsletter": true - Note that you get a 500 server error. If you add the missing brace, you'll get an expected response code (204 or 422).