diff --git a/ratelimit/core.py b/ratelimit/core.py index 7dce35e..9c2c941 100644 --- a/ratelimit/core.py +++ b/ratelimit/core.py @@ -24,7 +24,7 @@ async def default_429(scope: Scope, receive: Receive, send: Send) -> None: return default_429 -def _on_backend_error(err) -> ASGIApp: +def _on_backend_error(err: Exception) -> ASGIApp: async def default_503(scope: Scope, receive: Receive, send: Send) -> None: await send( { @@ -51,7 +51,7 @@ def __init__( *, on_auth_error: Optional[Callable[[Exception], Awaitable[ASGIApp]]] = None, on_blocked: Callable[[int], ASGIApp] = _on_blocked, - on_backend_error: Callable[[int], ASGIApp] = _on_backend_error, + on_backend_error: Callable[[Exception], ASGIApp] = _on_backend_error, ) -> None: self.app = app self.authenticate = authenticate diff --git a/ratelimit/exceptions/backend_connection.py b/ratelimit/exceptions.py similarity index 52% rename from ratelimit/exceptions/backend_connection.py rename to ratelimit/exceptions.py index cec419e..e868c83 100644 --- a/ratelimit/exceptions/backend_connection.py +++ b/ratelimit/exceptions.py @@ -1,4 +1,9 @@ -from .base_backend import BaseBackendException +class BaseBackendException(Exception): + """ + Base class for exception raised by Backends + """ + + pass class BackendConnectionException(BaseBackendException): diff --git a/ratelimit/exceptions/__init__.py b/ratelimit/exceptions/__init__.py deleted file mode 100644 index 7358eaa..0000000 --- a/ratelimit/exceptions/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# flake8: noqa: F401 -from .backend_connection import BackendConnectionException -from .base_backend import BaseBackendException diff --git a/ratelimit/exceptions/base_backend.py b/ratelimit/exceptions/base_backend.py deleted file mode 100644 index 4bc8abb..0000000 --- a/ratelimit/exceptions/base_backend.py +++ /dev/null @@ -1,6 +0,0 @@ -class BaseBackendException(Exception): - """ - Base class for exception raised by Backends - """ - - pass diff --git a/tests/test_core.py b/tests/test_core.py index a458462..c5f3e5a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -179,7 +179,7 @@ async def test_custom_on_backend_error(): assert response.text == "custom 503 page" -def yourself_503(retry_after: int): +def yourself_503(err: Exception): async def inside_yourself_503(scope: Scope, receive: Receive, send: Send) -> None: await send({"type": "http.response.start", "status": 503}) await send(