Skip to content
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

Simplify code of http_exception_handler #5323

Closed
wants to merge 3 commits into from

Conversation

PipeKnight
Copy link

Looking to JSONResponse.__init__() function, you can see that headers parameter is None by default, so it doesn't matter do we pass it here as None or do not pass at all. That's why we can safely remove this if-else expression and slightly simplify the code

Looking to `JSONResponse.__init__()` function, you can see that `headers` parameter is `None` by default, so it doesn't matter do we pass it here as `None` or do not pass at all. That's why we can safely remove this if-else expression and slightly simplify the code
@codecov
Copy link

codecov bot commented Aug 30, 2022

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (cf73051) 100.00% compared to head (3cfb1c3) 100.00%.
Report is 749 commits behind head on master.

❗ Current head 3cfb1c3 differs from pull request most recent head 089071a. Consider uploading reports for the commit 089071a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##            master     #5323    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          540       538     -2     
  Lines        13969     13869   -100     
==========================================
- Hits         13969     13869   -100     
Files Coverage Δ
fastapi/exception_handlers.py 100.00% <100.00%> (ø)

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

📝 Docs preview for commit e9fd538 at: https://630e16343174f0607e6e27a3--fastapi.netlify.app

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2022

📝 Docs preview for commit 3cfb1c3 at: https://631224982328a715fc06019d--fastapi.netlify.app

Copy link
Contributor

@iudeen iudeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ramnes
Copy link

ramnes commented Dec 9, 2022

LGTM but you probably can close it, it doesn't make sense anymore with the latest implementation of http_exception_handler from #5365:

async def http_exception_handler(request: Request, exc: HTTPException) -> Response:
headers = getattr(exc, "headers", None)
if not is_body_allowed_for_status_code(exc.status_code):
return Response(status_code=exc.status_code, headers=headers)
return JSONResponse(
{"detail": exc.detail}, status_code=exc.status_code, headers=headers
)

@tiangolo
Copy link
Owner

Thanks @PipeKnight! 🍰

And thanks everyone for the reviews and comments.

It seems this was covered in a recent change, so I'll close this one. But thanks for the effort! ☕

@tiangolo tiangolo closed this Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants