flask icon indicating copy to clipboard operation
flask copied to clipboard

docs: clarify 415 vs 400 errors for request.json

Open adityasah104 opened this issue 3 months ago • 5 comments

Description

Clarifies the distinction between 415 and 400 error codes when using request.json, aligning the JavaScript patterns documentation with the API reference.

Changes

  • Updated "Receiving JSON in Views" section to specify:
    • 400 Bad Request: for invalid JSON body
    • 415 Unsupported Media Type: for missing/incorrect Content-Type header
  • Updated "Making a Request with fetch" section for consistency

Fixes

Fixes #5825

Checklist

  • [x] Documentation updated
  • [x] Changes align with existing API documentation

adityasah104 avatar Oct 09 '25 07:10 adityasah104

Hey @adityasah104, I see you have edited the line quite a bit. Why not to keep it as it is and just edit the error message?

As example: Use the json property of the request object to decode the request’s body as JSON. If the body is not valid JSON, or the Content-Type header is not set to application/json, a ~400 Bad Request~ 415 Unsupported Media Type error will be raised.

How about changing it this way? 🙂

lonelyH3b avatar Dec 02 '25 15:12 lonelyH3b

@lonelyH3b because that's not accurate, as described in the issue, in the PR description, and in the code.

davidism avatar Dec 02 '25 15:12 davidism

Yes, got it ❤️

lonelyH3b avatar Dec 02 '25 15:12 lonelyH3b

Thanks @davidism for clarifying! The PR is ready for review whenever you have time.

adityasah104 avatar Dec 03 '25 10:12 adityasah104

@davidism Just wanted to gently follow up on this when you have a chance. Happy to make any additional changes if needed!

adityasah104 avatar Dec 03 '25 10:12 adityasah104