-
Notifications
You must be signed in to change notification settings - Fork 119
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 http 429 error handling #189
Add http 429 error handling #189
Conversation
The matrix.org server returns HTTP 429 TOO MANY REQUESTS error in this format: {'errcode': 'M_UNKNOWN', 'error': '{"errcode":"M_LIMIT_EXCEEDED","error":"Too Many Requests","retry_after_ms":3438}'} Which would cause an KeyError So I made some change to fix the error and added error handling to prevent an uncaught error caused by a non-standard server response.
I believe this is addressing same bug as #193. @eternal-flame-AD are you seeing this behavior on all 429 responses or just a subset of them? |
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.
Thanks for taking the time to fix this. Really appreciate it.
@@ -45,13 +45,14 @@ class MatrixHttpApi(object): | |||
response = matrix.send_message("!roomid:matrix.org", "Hello!") | |||
""" | |||
|
|||
def __init__(self, base_url, token=None, identity=None): | |||
def __init__(self, base_url, token=None, identity=None, default_429_wait_ms=5000): |
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.
Please add documentation on this kwarg to the docstring. After that, I can
certainly merge this; hopefully the weird behavior from Synapse will be fixed
upstream soon, and then we can remove at least a bit of this logic.
(We'll keep #193 open even after merging this to track the upstream issue with Synapse.) |
I saw this behaviour every time I triggered a 429 response at matrix.org home server. |
Update the documentation for default_429_wait_ms kwarg
LGTM. Thanks! |
This pull request included an error handling process while handling HTTP 429 TOO MANY REQUESTS error.
Here's a sample of matrix.org's HTTP 429 reply:
Which would cause an uncaught KeyError in the original implementation.
Also, in order to deal with other non-standard 429 replies, I added a default_429_wait_ms=5000 attribute to be used as a default waiting time if the server didn't provide one.
Signed-off-by: Andy Fu webmaster@andycloud.dynu.net