First Check
Commit to Help
Example Code
Description
I think that the response to a request with syntactically invalid JSON should be 400, not 422. This is the feature request I would prefer. But I would be willing to write a custom exception handler for now, if that were feasible.
Wanted Solution
In FastAPI/routing.py line 210-211, we have
except json.JSONDecodeError as e:
raise RequestValidationError([ErrorWrapper(e, ("body", e.pos))], body=e.doc)
I propose that the original exception not be discarded, by raising from --
except json.JSONDecodeError as e:
raise RequestValidationError([ErrorWrapper(e, ("body", e.pos))], body=e.doc) from e
With the original exception included, it would be simple enough to write a custom exception handler to handle the request as I see fit. This change should not break anyone's code, and I think it is generally the better practice to use raise from in such situations.
Wanted Code
Alternatives
No response
Operating System
Linux, macOS
Operating System Details
No response
FastAPI Version
0.63.0
Python Version
3.9.5
Additional Context
No response
First Check
Commit to Help
Example Code
Description
I think that the response to a request with syntactically invalid JSON should be 400, not 422. This is the feature request I would prefer. But I would be willing to write a custom exception handler for now, if that were feasible.
Wanted Solution
In FastAPI/routing.py line 210-211, we have
I propose that the original exception not be discarded, by raising from --
With the original exception included, it would be simple enough to write a custom exception handler to handle the request as I see fit. This change should not break anyone's code, and I think it is generally the better practice to use raise from in such situations.
Wanted Code
Alternatives
No response
Operating System
Linux, macOS
Operating System Details
No response
FastAPI Version
0.63.0
Python Version
3.9.5
Additional Context
No response