Skip to content

Fix: validate retry.afterStatusCodes is an array#868

Open
JSap0914 wants to merge 1 commit into
sindresorhus:mainfrom
JSap0914:fix/validate-after-status-codes-as-array
Open

Fix: validate retry.afterStatusCodes is an array#868
JSap0914 wants to merge 1 commit into
sindresorhus:mainfrom
JSap0914:fix/validate-after-status-codes-as-array

Conversation

@JSap0914

Copy link
Copy Markdown

Bug

retry.methods and retry.statusCodes both validate that the provided value is an array at construction time, throwing a descriptive error immediately. retry.afterStatusCodes was missing this same guard.

Passing a non-array (e.g. a single status code number) silently passes through normalizeRetryOptions and only fails later inside #calculateRetryDelay as a confusing:

TypeError: this.#options.retry.afterStatusCodes.includes is not a function

This error appears during a retry attempt — well after construction — making it hard to diagnose.

Fix

Add the missing validation to normalizeRetryOptions so all three array options are consistent:

if (retry.afterStatusCodes && !Array.isArray(retry.afterStatusCodes)) {
    throw new Error('retry.afterStatusCodes must be an array');
}

Verification

npx ava test/retry.ts --match '*afterStatusCodes is not an array*'

Result: 1 test passed (new test). Full npx ava test/retry.ts: 85 tests passed, 0 failed.

AI-assisted contribution.

retry.methods and retry.statusCodes both validate that the provided value
is an array, throwing a clear error at construction time when it is not.
retry.afterStatusCodes was missing this same guard: passing a non-array
(e.g. a single number) silently slipped through normalizeRetryOptions,
and only surfaced as a confusing TypeError deep inside #calculateRetryDelay
when .includes() was called on a non-array.

Adds the missing validation to keep all three options consistent.
Copilot AI review requested due to automatic review settings June 18, 2026 17:35

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sholladay sholladay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If I'm not mistaken, this test would also pass on the main branch.

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