refactor: simplify condition (#2775)
This commit is contained in:
parent
09b1623bb0
commit
edfd297bf3
1 changed files with 21 additions and 23 deletions
|
|
@ -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"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue