diff --git a/src/tap_intacct/client.py b/src/tap_intacct/client.py index 58ec71c..5205441 100644 --- a/src/tap_intacct/client.py +++ b/src/tap_intacct/client.py @@ -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() @@ -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: @@ -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}') @@ -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]: