Skip to content

chore: add retry configuration options for http requests#198

Draft
duyhungtnn wants to merge 12 commits intomasterfrom
chore/retry-on-499
Draft

chore: add retry configuration options for http requests#198
duyhungtnn wants to merge 12 commits intomasterfrom
chore/retry-on-499

Conversation

@duyhungtnn
Copy link
Copy Markdown
Collaborator

@duyhungtnn duyhungtnn commented Apr 14, 2026

#199
This pull request introduces a robust and configurable retry mechanism for HTTP requests, including support for the Retry-After header, exponential backoff with jitter, and comprehensive configuration validation and defaults. It also adds extensive unit tests to ensure correct parsing and propagation of retry-related logic throughout the codebase.

Retry logic and error handling improvements:

  • Added a new promiseRetriable utility in src/utils/promiseRetriable.ts that provides generic, configurable retry logic with exponential backoff and jitter, as well as logic to respect the Retry-After header and classify retryable errors and status codes.
  • Enhanced the InvalidStatusError class in src/objects/errors.ts to include an optional retryAfterMs property, and added a parseRetryAfter function to parse both delta-seconds and HTTP-date formats from the Retry-After header.
  • Updated the HTTP client in src/api/client.ts to parse the Retry-After header from error responses and propagate it via InvalidStatusError, ensuring that retry logic can use this information. [1] [2]

Configuration and validation:

  • Introduced new retry-related configuration options (maxRetries, retryInitialInterval, retryMaxInterval) to the BKTConfig interface in src/config.ts, with sensible defaults and validation logic to handle negative or inconsistent values. [1] [2] [3] [4] [5]
  • Updated test configuration helpers and conversion logic to reflect and test these new retry options. [1] [2] [3]

Introduce promiseRetriable with a RetryPolicy and ShouldRetryFn, supporting linear (default) and constant backoff strategies. Implements a retry loop honoring maxRetries and delay, a sleep helper, and backoff delay calculation. Add AVA + sinon tests validating successful retries, delay behavior, exceeding max retries, shouldRetry gating, mid-sequence stop, and both linear and constant backoff strategies.
@duyhungtnn duyhungtnn changed the title feat: add promiseRetriable utility and tests chore: add retry configuration options for http requests Apr 15, 2026
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