Skip to content

Commit

Permalink
Fix typing, move exceptions to single file
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharat23 committed Jul 31, 2024
1 parent 5eaed8c commit b8c3ff6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ratelimit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from .base_backend import BaseBackendException
class BaseBackendException(Exception):
"""
Base class for exception raised by Backends
"""

pass


class BackendConnectionException(BaseBackendException):
Expand Down
3 changes: 0 additions & 3 deletions ratelimit/exceptions/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions ratelimit/exceptions/base_backend.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b8c3ff6

Please sign in to comment.