Skip to content

Commit

Permalink
add backoff for 400 and 500 (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyn4 authored Aug 8, 2024
1 parent 607bb20 commit 8e014d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tap_quickbooks/quickbooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tap_quickbooks/quickbooks/rest_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e014d0

Please sign in to comment.