diff --git a/qds_sdk/connection.py b/qds_sdk/connection.py index eea6fe32..3ec4c0a8 100644 --- a/qds_sdk/connection.py +++ b/qds_sdk/connection.py @@ -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) @@ -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) diff --git a/qds_sdk/exception.py b/qds_sdk/exception.py index ef06a335..5f545a30 100644 --- a/qds_sdk/exception.py +++ b/qds_sdk/exception.py @@ -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