-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: master
Are you sure you want to change the base?
Conversation
@abersheeran Can I get a review for this PR? Thanks |
@@ -0,0 +1,3 @@ | |||
# flake8: noqa: F401 | |||
from .backend_connection import BackendConnectionException |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
Changes
exception
folder to store all the custom exception classescore.py
to catchBaseBackendException
on_backend_error
toRateLimitMiddleware
, defaults to_on_backend_error
and can be modified by enduser by passing their custom functionRedisBackend
to catch ConnectionError raised by redis and raise custom exception instead_on_backend_error
function.