Skip to content

feat: Implement retry mechanism for transient API failures - #18

Merged
danieyal merged 3 commits into
masterfrom
danieyal/02072026-1
Jul 2, 2026
Merged

feat: Implement retry mechanism for transient API failures#18
danieyal merged 3 commits into
masterfrom
danieyal/02072026-1

Conversation

@danieyal

@danieyal danieyal commented Jul 2, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a robust retry mechanism for transient API and network errors in both the legacy and REST clients, improving reliability when communicating with the myTNB APIs. The main changes include a new with_retry helper with exponential backoff, integration of this helper into client methods, and comprehensive tests to ensure correct retry behavior.

Retry mechanism implementation:

  • Added a new module retry.py implementing with_retry, a bounded retry helper with exponential backoff for transient HTTP status codes (e.g., 404, 5xx) and network errors, and defined RETRYABLE_STATUS_CODES.
  • Updated the APIError exception to include a retryable flag, allowing errors to signal if they should be retried.

Integration into client code:

  • Refactored both legacy.py and rest.py clients to wrap API calls with with_retry, raising retryable APIError on transient status codes and ensuring only safe errors are retried. [1] [2] [3] [4] [5] [6] [7]

Testing and validation:

  • Added unit tests in test_retry.py to verify the retry logic, including correct handling of retryable and non-retryable errors and network exceptions.
  • Extended test_client.py with tests for legacy client retry behavior on transient and persistent 404 errors, and adjusted imports for the new retry constants. [1] [2]

These changes collectively improve the resilience of the client against intermittent backend failures, ensuring transient issues do not unnecessarily surface as hard errors to the caller.

Copilot AI review requested due to automatic review settings July 2, 2026 03:07
@danieyal danieyal self-assigned this Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a bounded retry helper with exponential backoff for transient transport/API failures and integrates it into the legacy and REST transports, with a small extension to APIError to mark errors as retryable.

Changes:

  • Introduces mytnb.client.retry.with_retry() plus RETRYABLE_STATUS_CODES and defaults for attempts/delay.
  • Extends APIError with a retryable flag and uses it to drive retry decisions.
  • Wraps legacy and REST transport requests with the retry helper and adds/extends tests for retry behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/mytnb/client/retry.py New retry helper with exponential backoff + retryability rules.
src/mytnb/exceptions.py Adds retryable flag to APIError to support retry signaling.
src/mytnb/client/legacy.py Wraps legacy ASMX calls with with_retry and marks transient HTTP statuses retryable.
src/mytnb/client/rest.py Wraps REST GET/POST with with_retry and converts retryable statuses into retryable APIError.
tests/test_retry.py New unit tests validating retry helper behavior and constants.
tests/test_client.py Adds legacy-transport retry tests and imports retry defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mytnb/client/retry.py
Comment thread src/mytnb/client/rest.py
@danieyal
danieyal merged commit ce19c08 into master Jul 2, 2026
6 checks passed
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.

2 participants