Skip to content

Commit

Permalink
@giancarloromeo review: changed signature to make mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 31, 2024
1 parent afd3bbe commit be23200
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

async def http_exception_handler(request: Request, exc: Exception) -> JSONResponse:
assert request # nosec
assert isinstance(exc, HTTPException)
assert isinstance(exc, HTTPException) # nosec

return create_error_json_response(exc.detail, status_code=exc.status_code)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


def setup_exception_handlers(app: FastAPI) -> None:
app.add_exception_handler(HTTPException, http_error_handler) # type: ignore[arg-type]
app.add_exception_handler(RequestValidationError, http422_error_handler) # type: ignore[arg-type]
app.add_exception_handler(HTTPException, http_error_handler)
app.add_exception_handler(RequestValidationError, http422_error_handler)

# SEE https://docs.python.org/3/library/exceptions.html#exception-hierarchy
app.add_exception_handler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from starlette.types import HTTPExceptionHandler


async def http_error_handler(_: Request, exc: HTTPException) -> JSONResponse:
async def http_error_handler(request: Request, exc: Exception) -> JSONResponse:
assert request # nosec
assert isinstance(exc, HTTPException) # nosec

return JSONResponse(
content=jsonable_encoder({"errors": [exc.detail]}), status_code=exc.status_code
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
from fastapi.openapi.constants import REF_PREFIX
from fastapi.openapi.utils import validation_error_response_definition
from pydantic import ValidationError
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY


async def http422_error_handler(
_: Request,
exc: RequestValidationError | ValidationError,
) -> JSONResponse:
async def http422_error_handler(_: Request, exc: Exception) -> JSONResponse:
assert hasattr(exc, "errors") # nosec
return JSONResponse(
content=jsonable_encoder({"errors": exc.errors()}),
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
Expand Down

0 comments on commit be23200

Please sign in to comment.