-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
Open
Labels
Description
Documentation on "json" request throwing a 415 as well as 400.
The problem text is on https://flask.palletsprojects.com/en/stable/patterns/javascript/#receiving-json-in-views
Receiving JSON in Views
Use the [json](https://flask.palletsprojects.com/en/stable/api/#flask.Request.json) property of the [request](https://flask.palletsprojects.com/en/stable/api/#flask.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 error will be raised
I believe you want to indicate that it's a 415 instead of 400 when the Content-Type header doesn't match as it's done on https://flask.palletsprojects.com/en/stable/api/#flask.Request.json
400 is still valid for when the body isn't json (even though the content-type is json).
So maybe something like this ?
Receiving JSON in Views
Use the [json](https://flask.palletsprojects.com/en/stable/api/#flask.Request.json) property of the [request](https://flask.palletsprojects.com/en/stable/api/#flask.request) object to decode the request’s body as JSON. If the body is not valid JSON, a 400 Bad Request error will be raised. If the Content-Type header is not set to application/json, a 415 Unsupported Media Type error will be raised
Environment:
- Python version: N/A
- Flask version: latest doc
This is in no way a bug, but it's for being aligned everywhere in your doc :). I'm just trying to make things better, I love the product ! thanks for the great work you've done !