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 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" 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 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,