Skip to content

Commit

Permalink
Add backoff in case of an error that have the crrection sugested to b…
Browse files Browse the repository at this point in the history
…e a retry (#17)
  • Loading branch information
butkeraites-hotglue authored Oct 8, 2024
1 parent 76c4557 commit 56676c5
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit 56676c5

Please sign in to comment.