diff --git a/tap_quickbooks/quickbooks/__init__.py b/tap_quickbooks/quickbooks/__init__.py index f54507d..1e83f58 100644 --- a/tap_quickbooks/quickbooks/__init__.py +++ b/tap_quickbooks/quickbooks/__init__.py @@ -269,6 +269,8 @@ def field_to_property_schema(field, mdata): # pylint:disable=too-many-branches return property_schema, mdata +class RetriableApiError(Exception): + pass class Quickbooks(): # pylint: disable=too-many-instance-attributes,too-many-arguments @@ -370,7 +372,7 @@ def check_rest_quota_usage(self, headers): # pylint: disable=too-many-arguments @backoff.on_exception(backoff.expo, - requests.exceptions.ConnectionError, + (requests.exceptions.ConnectionError,RetriableApiError), max_tries=10, factor=2, on_backoff=log_backoff_attempt) @@ -384,6 +386,12 @@ def _make_request(self, http_method, url, headers=None, body=None, stream=False, else: raise TapQuickbooksException("Unsupported HTTP method") + if ( + resp.status_code == 500 + and resp.text + == "Authorization FailureAuthorizationFailure: Unknown Error during Authentication, statusCode: 500" + ) or resp.status_code in [400]: + raise RetriableApiError(resp.text) try: resp.raise_for_status() except RequestException as ex: diff --git a/tap_quickbooks/quickbooks/rest_reports.py b/tap_quickbooks/quickbooks/rest_reports.py index 0c5f4e1..96e7ab6 100644 --- a/tap_quickbooks/quickbooks/rest_reports.py +++ b/tap_quickbooks/quickbooks/rest_reports.py @@ -14,7 +14,7 @@ def is_fatal_code(e: requests.exceptions.RequestException) -> bool: '''Helper function to determine if a Requests reponse status code is a "fatal" status code. If it is, the backoff decorator will giveup instead of attemtping to backoff.''' - return 400 <= e.response.status_code < 500 and e.response.status_code != 429 + return 400 <= e.response.status_code < 500 and e.response.status_code not in [429, 400] class RetriableException(Exception): pass