Skip to content

Commit

Permalink
SDK-386: Add New Exception Class for 429 errors (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekharsaurabh authored and chattarajoy committed Feb 18, 2020
1 parent ff6dccb commit 439b882
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit 439b882

Please sign in to comment.