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 http 429 error handling #189

Merged
merged 5 commits into from
Apr 18, 2018
Merged

Add http 429 error handling #189

merged 5 commits into from
Apr 18, 2018

Conversation

eternal-flame-AD
Copy link
Contributor

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:

{'errcode':'M_UNKNOWN', 'error': '{"errcode":"M_LIMIT_EXCEEDED","error":"Too Many Requests","retry_after_ms":3438}'}

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

_eternal_flame added 3 commits April 3, 2018 17:28
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.
@non-Jedi
Copy link
Collaborator

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?

Copy link
Collaborator

@non-Jedi non-Jedi left a 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):
Copy link
Collaborator

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.

@non-Jedi
Copy link
Collaborator

(We'll keep #193 open even after merging this to track the upstream issue with Synapse.)

@eternal-flame-AD
Copy link
Contributor Author

I saw this behaviour every time I triggered a 429 response at matrix.org home server.

_eternal_flame added 2 commits April 18, 2018 10:41
Update the documentation for default_429_wait_ms kwarg
@non-Jedi
Copy link
Collaborator

LGTM. Thanks!

@non-Jedi non-Jedi merged commit 444806a into matrix-org:master Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants