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