Skip to content

Fix API error handling and unnecessary reauthorization - #3

Open
econstantin wants to merge 2 commits into
sstallion:masterfrom
econstantin:codex/api-failure-handling
Open

econstantin wants to merge 2 commits into
sstallion:masterfrom
econstantin:codex/api-failure-handling

Conversation

@econstantin

@econstantin econstantin commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Context

API failures can lose their original error type, trigger repeated authorization attempts, or unnecessarily discard a valid access token.

Repro steps

Using mocked responses:

  1. Call async_samples() when authorization fails.
  2. Return an HTTP error with an empty or non-JSON body.
  3. After successful authorization, return a connection timeout or HTTP 503.

Expected

Preserve authentication errors, report other failures as library errors, and retain valid tokens after connection or server failures.

Actual

Authorization failures are retried again by the calling method and become general errors. Unexpected response bodies can cause parsing errors. Connection and server failures force reauthorization.

Fix

  • Preserve errors already handled by the library.
  • Handle unexpected error bodies safely.
  • Expire tokens only for HTTP 400, 401, or 403.
  • Stop immediate retries of HTTP 4xx responses; report other 4xx responses, including 429, as general errors.

Testing

  • All 13 tests pass on Python 3.12 and 3.13.
  • Both CI jobs pass, including package builds.
  • Regression tests cover error types, response bodies, retry counts, and token reuse.
  • Tests use mocked responses; no live SensorPush requests were made.

Notes

Depends on #2. The current diff includes its test and packaging baseline. Rebase after #2 merges to leave only the API changes, tests, and changelog entries.

HTTP 400 remains an authentication error, matching existing behavior. Retry count and timing for connection and server failures are unchanged.

@econstantin
econstantin marked this pull request as ready for review October 23, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant