refactor: simplify condition (#2775)

This commit is contained in:
Vlad Stan 2024-11-13 10:28:46 +02:00 committed by GitHub
parent 09b1623bb0
commit edfd297bf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,11 +26,11 @@ class InvoiceError(Exception):
def render_html_error(request: Request, exc: Exception) -> Optional[Response]:
# Only the browser sends "text/html" request
# not fail proof, but everything else get's a JSON response
if (
request.headers
and "accept" in request.headers
and "text/html" in request.headers["accept"]
):
if not request.headers:
return None
if "text/html" not in request.headers.get("accept", ""):
return None
if (
isinstance(exc, HTTPException)
and exc.headers
@ -52,8 +52,6 @@ def render_html_error(request: Request, exc: Exception) -> Optional[Response]:
request, "error.html", {"err": f"Error: {exc!s}"}, status_code
)
return None
def register_exception_handlers(app: FastAPI):
"""Register exception handlers for the FastAPI app"""