Skip to content

feat(http): retry requests on transient error status codes#104

Merged
dorsha merged 3 commits into
mainfrom
feat/retry-on-transient-errors
Mar 23, 2026
Merged

feat(http): retry requests on transient error status codes#104
dorsha merged 3 commits into
mainfrom
feat/retry-on-transient-errors

Conversation

@dorsha

@dorsha dorsha commented Mar 23, 2026

Copy link
Copy Markdown
Member

Summary

https://github.com/descope/etc/issues/14039

  • Retry on 503, 521, 522, 524, 530 with delays of 100ms → 5s → 5s (max 3 retries)
  • Adds executeWithRetry() helper used by doPost, doGet, and doDelete
  • Retry delays stored in a protected property so tests can override without actual sleeps
  • 7 new PHPUnit tests covering all retryable codes, exhaustion, per-method coverage, and no-retry on non-retryable codes

🤖 Generated with Claude Code

Retry on 503, 521, 522, 524, 530 with delays of 100ms, 5s, 5s (max 3
retries). Adds executeWithRetry() helper used by doPost, doGet, and
doDelete. Delays are a protected array for easy test overriding.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 23, 2026 10:36
@shuni-bot-dev

shuni-bot-dev Bot commented Mar 23, 2026

Copy link
Copy Markdown

🐕 Review complete — View session on Shuni Portal 🐾

@dorsha dorsha enabled auto-merge (squash) March 23, 2026 10:36
@dorsha dorsha requested a review from gaokevin1 March 23, 2026 10:36

@shuni-bot-dev shuni-bot-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🐕 Shuni's Review

Adds retry logic for transient HTTP status codes (503, 521, 522, 524, 530) with configurable delays, applied to all three HTTP methods. Tests are solid with good coverage of edge cases.

No issues found — good bones! Woof!

Comment thread src/SDK/API.php
…roperty lookup

- Remove ZeroDelayAPI subclass (PSR2 requires one class per file)
- Use ReflectionClass(API::class) to access private httpClient and
  protected retryDelaysUs on the parent class, matching the pattern
  used by APIExceptionMappingTest

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

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

Adds automatic retry behavior for HTTP requests that fail with specific transient status codes, and extends the PHPUnit suite to cover the new behavior.

Changes:

  • Introduces an executeWithRetry() helper in API and routes doGet, doPost, and doDelete through it.
  • Adds a new PHPUnit test file validating retry behavior (success after retries, exhaustion, and non-retry cases).
  • Updates phpunit.xml to include additional test files in the executed suite.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
src/SDK/API.php Adds retry helper + wraps GET/POST/DELETE requests to retry on transient status codes.
src/tests/APIRetryTest.php New tests verifying retry behavior and retry exhaustion behavior.
phpunit.xml Ensures retry/mapping tests are actually run by the test suite.

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

Comment thread src/SDK/API.php Outdated
Comment thread src/tests/APIRetryTest.php
Comment thread src/tests/APIRetryTest.php
Comment thread src/SDK/API.php Outdated
Comment thread src/SDK/API.php Outdated
Comment thread src/SDK/API.php Outdated
Comment thread src/SDK/API.php Outdated
Comment thread src/SDK/API.php Outdated
- Remove typed property declaration (array) and numeric separators from
  retryDelaysUs — requires PHP 7.4+
- Remove mixed return type from executeWithRetry — requires PHP 8.0+
- Replace nullsafe operator (?->) with explicit null check — requires PHP 8.0+
- Replace arrow functions (fn() =>) with traditional closures — requires PHP 7.4+
- Fix testDoesNotRetryOnNonRetryableStatusCodes: assert via (string)$e
  instead of getStatusCode() which does not exist on AuthException

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dorsha dorsha merged commit 4c6d78c into main Mar 23, 2026
12 checks passed
@dorsha dorsha deleted the feat/retry-on-transient-errors branch March 23, 2026 18:40
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.

3 participants