From 31034f81bd6446c73709dc2ca96b2fbe5c554193 Mon Sep 17 00:00:00 2001 From: Sebastian Smiley Date: Tue, 7 Jan 2025 15:58:55 -0500 Subject: [PATCH] 401/404 fix for auth and non-existant us tax profiles --- tap_adp/authenticator.py | 4 +++- tap_adp/streams.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tap_adp/authenticator.py b/tap_adp/authenticator.py index 7087baa..916ced3 100644 --- a/tap_adp/authenticator.py +++ b/tap_adp/authenticator.py @@ -70,7 +70,9 @@ def update_access_token(self) -> None: token_json = response.json() self.access_token = token_json["access_token"] - expiration = token_json.get("expires_in", self._default_expiration) + # subtract 10 minutes from the expiration to allow additional time for + # reauthentication to occur. + expiration = token_json.get("expires_in", self._default_expiration) - 600 self.expires_in = int(expiration) if expiration else None if self.expires_in is None: diff --git a/tap_adp/streams.py b/tap_adp/streams.py index d58898c..bf8f633 100644 --- a/tap_adp/streams.py +++ b/tap_adp/streams.py @@ -110,16 +110,16 @@ class USTaxProfileStream(ADPStream): schema_filepath = SCHEMAS_DIR / "us_tax_profile.json" parent_stream_type=WorkersStream - # We're getting inconsistent 401 and 404 errors, not sure why. - extra_retry_statuses = [ - HTTPStatus.TOO_MANY_REQUESTS, - HTTPStatus.NOT_FOUND, - HTTPStatus.UNAUTHORIZED, - ] - - + def parse_response(self, response: requests.Response) -> t.Iterable[dict]: + if response.status_code == HTTPStatus.NOT_FOUND: + return iter([]) + return super().parse_response(response) def validate_response(self, response): + if response.status_code == HTTPStatus.NOT_FOUND: + msg = f"No US tax profile found for path: {response.request.path_url}" + self.logger.warning(msg) + return try: response_json = response.json() except requests.JSONDecodeError: