Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Better JSON Decode error handling#1354

Merged
tiangolo merged 3 commits into
fastapi:masterfrom
aviramha:handle_json_error
Jun 13, 2020
Merged

Better JSON Decode error handling#1354
tiangolo merged 3 commits into
fastapi:masterfrom
aviramha:handle_json_error

Conversation

@aviramha

Copy link
Copy Markdown
Contributor

I was annoyed by the fact that if JSON parsing fails for the body you receive HTTP Exception 400.
I think RequestValidationError is a better suit for the case, for the client to realize what have he done wrong exactly (position of wrong character) and body to be part of the exception (so it can be logged)

@codecov

codecov Bot commented Apr 30, 2020

Copy link
Copy Markdown

Codecov Report

Merging #1354 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1354   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          226       227    +1     
  Lines         6785      6813   +28     
=========================================
+ Hits          6785      6813   +28     
Impacted Files Coverage Δ
fastapi/routing.py 100.00% <100.00%> (ø)
tests/test_tutorial/test_body/test_tutorial001.py 100.00% <100.00%> (ø)
fastapi/applications.py 100.00% <0.00%> (ø)
...orial/test_conditional_openapi/test_tutorial001.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e77737...abe1cd9. Read the comment docs.

@aviramha

Copy link
Copy Markdown
Contributor Author

@tiangolo Seems the new handling leaves the generic exception handling uncovered. Not sure how to trigger that exception now tho, would assume connection breaking or something similar. ideas?

@aviramha

Copy link
Copy Markdown
Contributor Author

Added missing test for full coverage, pending CR @tiangolo .

@tiangolo tiangolo merged commit b13a4ba into fastapi:master Jun 13, 2020
@tiangolo

Copy link
Copy Markdown
Member

Awesome! Very nice 👌 ✨

Impeccable implementation and tests ✔️ 🚀

Thanks for your contribution! 🎉 🍰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants