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

401/404 fix for auth and non-existant us tax profiles #12

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
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
Loading