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

fix:dev:SDK-386: Add new exception for 429 errors #302

Merged
merged 25 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions qds_sdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ def f_retry(self, *args, **kwargs):
return f_retry # true decorator
return deco_retry

@retry((RetryWithDelay, requests.Timeout))
@retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry))
def get_raw(self, path, params=None):
return self._api_call_raw("GET", path, params=params)

@retry((RetryWithDelay, requests.Timeout, ServerError))
@retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry))
def get(self, path, params=None):
return self._api_call("GET", path, params=params)

@retry((RetryWithDelay, requests.Timeout))
@retry(ApiThrottledRetry)
def put(self, path, data=None):
return self._api_call("PUT", path, data)

@retry((RetryWithDelay, requests.Timeout))
@retry(ApiThrottledRetry)
def post(self, path, data=None):
return self._api_call("POST", path, data)

@retry((RetryWithDelay, requests.Timeout))
@retry(ApiThrottledRetry)
def delete(self, path, data=None):
return self._api_call("DELETE", path, data)

Expand Down Expand Up @@ -196,7 +196,7 @@ def _handle_error(response):
raise RetryWithDelay(response, "Data requested is unavailable. Retrying...")
elif code == 429:
sys.stderr.write(response.text + "\n")
raise RetryWithDelay(response, "Too many requests. Retrying...")
raise ApiThrottledRetry(response, "Too many requests. Retrying...")
elif 401 <= code < 500:
sys.stderr.write(response.text + "\n")
raise ClientError(response)
Expand Down
6 changes: 6 additions & 0 deletions qds_sdk/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ class MethodNotAllowed(ClientError):
"""An error raised when a method is not allowed."""
# 405 Method Not Allowed
pass


class ApiThrottledRetry(ClientError):
"""An error raised when upstream requests are throttled."""
# 429 Too Many Requests
pass