New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve json.JSONDecodeError when handling invalid JSON in request body #3993
Comments
Is this currently being worked on @declaresub ? |
I don't know. I would be happy to do it, but this is the first issue I've submitted to fastapi, and with 389 open pull requests, I didn't see the point spending time on a pull request that would never be looked at. |
Thanks for posting it @declaresub! And thanks @UKnowWhoIm for the PR! 🎉 🍰 This should be solved in #4057 and will be available in the next version, released in some hours or the next days. (the current latest is |
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
I know this is an old ticket, but isn't it |
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
The text was updated successfully, but these errors were encountered: