Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backoff in case of an error that have the crrection sugested to retry #17

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/tap_intacct/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
AuthFailure
)

class PleaseTryAgainLaterError(Exception):
pass

from .const import GET_BY_DATE_FIELD, INTACCT_OBJECTS, KEY_PROPERTIES, REP_KEYS

logger = singer.get_logger()
Expand Down Expand Up @@ -127,7 +130,7 @@ def _set_session_id(self, user_id: str, company_id: str, user_password: str):

@singer.utils.ratelimit(10, 1)
@backoff.on_exception(backoff.expo,
(ExpatError),
(ExpatError, PleaseTryAgainLaterError),
max_tries=5,
factor=2)
def _post_request(self, dict_body: dict, api_url: str) -> Dict:
Expand Down Expand Up @@ -184,6 +187,8 @@ def _post_request(self, dict_body: dict, api_url: str) -> Dict:
return {"result": "skip_and_paginate"}

exception_msg = parsed_response.get("response", {}).get("errormessage", {}).get("error", {})
correction = exception_msg.get("correction", {})

if response.status_code == 400:
if exception_msg.get("errorno") == "GW-0011":
raise AuthFailure(f'One or more authentication values are incorrect. Response:{parsed_response}')
Expand All @@ -208,6 +213,9 @@ def _post_request(self, dict_body: dict, api_url: str) -> Dict:
if response.status_code == 500:
raise InternalServerError(f'Internal server error. Response: {parsed_response}')

if correction and 'Please Try Again Later' in correction:
raise PleaseTryAgainLaterError(parsed_response)

raise SageIntacctSDKError('Error: {0}'.format(parsed_response))

def support_id_msg(self, errormessages) -> Union[List, Dict]:
Expand Down
Loading