22from collections .abc import Callable
33from typing import Awaitable
44
5- from fastapi import HTTPException , Request , status
5+ from fastapi import HTTPException , status
66from fastapi .encoders import jsonable_encoder
77from servicelib .logging_errors import create_troubleshotting_log_kwargs
88from servicelib .status_codes_utils import is_5xx_server_error
9+ from starlette .requests import Request
910from starlette .responses import JSONResponse
1011
1112from ...exceptions .errors import RutNotFoundError
@@ -34,8 +35,9 @@ async def http_error_handler(request: Request, exc: Exception) -> JSONResponse:
3435
3536def http404_error_handler (
3637 _ : Request , # pylint: disable=unused-argument
37- exc : RutNotFoundError ,
38+ exc : Exception ,
3839) -> JSONResponse :
40+ assert isinstance (exc , RutNotFoundError ) # nose
3941 return JSONResponse (
4042 status_code = status .HTTP_404_NOT_FOUND ,
4143 content = {"message" : f"{ exc .msg_template } " },
@@ -44,15 +46,15 @@ def http404_error_handler(
4446
4547def make_http_error_handler_for_exception (
4648 status_code : int , exception_cls : type [BaseException ]
47- ) -> Callable [[Request , type [ BaseException ] ], Awaitable [JSONResponse ]]:
49+ ) -> Callable [[Request , Exception ], Awaitable [JSONResponse ]]:
4850 """
4951 Produces a handler for BaseException-type exceptions which converts them
5052 into an error JSON response with a given status code
5153
5254 SEE https://docs.python.org/3/library/exceptions.html#concrete-exceptions
5355 """
5456
55- async def _http_error_handler (_ : Request , exc : type [ BaseException ] ) -> JSONResponse :
57+ async def _http_error_handler (_ : Request , exc : Exception ) -> JSONResponse :
5658 assert isinstance (exc , exception_cls ) # nosec
5759 return JSONResponse (
5860 content = jsonable_encoder ({"errors" : [str (exc )]}), status_code = status_code
0 commit comments