Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for backend error #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bharat23
Copy link

@Bharat23 Bharat23 commented Jun 6, 2024

Changes

  • Add a new exception folder to store all the custom exception classes
  • update core.py to catch BaseBackendException
  • Add new argument on_backend_error to RateLimitMiddleware , defaults to _on_backend_error and can be modified by enduser by passing their custom function
  • Update RedisBackend to catch ConnectionError raised by redis and raise custom exception instead
  • Add 2 test cases for backend error both with and without the use of custom _on_backend_error function.

@Bharat23
Copy link
Author

Bharat23 commented Jul 6, 2024

@abersheeran Can I get a review for this PR? Thanks

@@ -0,0 +1,3 @@
# flake8: noqa: F401
from .backend_connection import BackendConnectionException
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should put the exceptions in a file, it seems unnecessary to break them down for our codebase.

@@ -37,6 +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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint here is incorrect.

assert response.text == "custom 503 page"


def yourself_503(retry_after: int):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants