From fa3b3fd2d9115ec0790baed93bab9d64b7bb76ae Mon Sep 17 00:00:00 2001 From: Fatih Kurtoglu Date: Thu, 15 Apr 2021 11:28:01 -0700 Subject: [PATCH 1/4] bumped version --- scaleapi/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scaleapi/_version.py b/scaleapi/_version.py index ea1832b..d8b1bd8 100644 --- a/scaleapi/_version.py +++ b/scaleapi/_version.py @@ -1,2 +1,2 @@ -__version__ = "2.0.3" +__version__ = "2.0.4" __package_name__ = "scaleapi" From fb6f558c5ffb7699bb322b9d04614c929c3beaec Mon Sep 17 00:00:00 2001 From: Fatih Kurtoglu Date: Thu, 15 Apr 2021 11:28:25 -0700 Subject: [PATCH 2/4] type hinting for exception mapping --- scaleapi/exceptions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scaleapi/exceptions.py b/scaleapi/exceptions.py index b70206a..d429a9e 100644 --- a/scaleapi/exceptions.py +++ b/scaleapi/exceptions.py @@ -1,3 +1,6 @@ +from typing import Dict + + class ScaleException(Exception): """Generic ScaleException class""" @@ -81,7 +84,7 @@ class ScaleTimeoutError(ScaleException): code = 504 -ExceptionMap = { +ExceptionMap: Dict[int, ScaleException] = { ScaleInvalidRequest.code: ScaleInvalidRequest, ScaleUnauthorized.code: ScaleUnauthorized, ScaleNotEnabled.code: ScaleNotEnabled, From e129e9aa623b1e2fee9c11a79f773b517e383f2f Mon Sep 17 00:00:00 2001 From: Fatih Kurtoglu Date: Thu, 15 Apr 2021 11:29:31 -0700 Subject: [PATCH 3/4] retry for cloudflare error codes --- scaleapi/api.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scaleapi/api.py b/scaleapi/api.py index 4eab5e2..26af3ee 100644 --- a/scaleapi/api.py +++ b/scaleapi/api.py @@ -12,7 +12,19 @@ # Parameters for HTTP retry HTTP_TOTAL_RETRIES = 3 # Number of total retries HTTP_RETRY_BACKOFF_FACTOR = 2 # Wait 1, 2, 4 seconds between retries -HTTP_STATUS_FORCE_LIST = [429, 500, 503, 504] # Status codes to force retry +HTTP_STATUS_FORCE_LIST = [ + 429, + 500, + 502, + 503, + 504, + 520, + 521, + 522, + 523, + 524, + 525, +] # Status codes to force retry HTTP_RETRY_ALLOWED_METHODS = frozenset({"GET", "POST"}) @@ -73,11 +85,8 @@ def _raise_on_respose(res: Response): except ValueError: message = res.text - try: - exception = ExceptionMap[res.status_code] - raise exception(message) - except KeyError as err: - raise ScaleException(message, res.status_code) from err + exception = ExceptionMap.get(res.status_code, ScaleException) + raise exception(message, res.status_code) def _api_request( self, method, endpoint, headers=None, auth=None, params=None, body=None From 1051197ef6db4f392f26fe0ef7e3deb418a46cf0 Mon Sep 17 00:00:00 2001 From: Fatih Kurtoglu Date: Thu, 15 Apr 2021 11:30:22 -0700 Subject: [PATCH 4/4] circleci config update for pytest --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cbecb14..da31c5c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,7 +39,7 @@ jobs: - run: name: Pytest Test Cases command: | # Run test suite, uses SCALE_TEST_API_KEY env variable - pytest -v + pytest -v -s - run: name: Twine PyPI Check command: | # Validate distribution and setup.py configuration