Skip to content

Commit

Permalink
401/404 fix for auth and non-existant us tax profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianswms committed Jan 7, 2025
1 parent cb12c31 commit 31034f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tap_adp/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions tap_adp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 31034f8

Please sign in to comment.