Skip to content

Commit 6ba48af

Browse files
authored
Merge branch 'main' into ss/add-query-method-support
2 parents c73d3c3 + f37e82c commit 6ba48af

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ If `retry` is a number, it will be used as `limit` and other defaults will remai
294294

295295
Network errors (e.g., DNS failures, connection refused, offline) are automatically retried for retriable methods. Only errors recognized as network errors are retried; other errors (e.g., programming bugs) are thrown immediately. Use `shouldRetry` to customize this behavior.
296296

297-
If the response provides an HTTP status contained in `afterStatusCodes`, Ky will wait until the date, timeout, or timestamp given in the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header has passed to retry the request. If `Retry-After` is missing, the non-standard [`RateLimit-Reset`](https://www.ietf.org/archive/id/draft-polli-ratelimit-headers-05.html#section-3.3) header is used in its place as a fallback. If the provided status code is not in the list, the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header will be ignored.
297+
If the response provides an HTTP status contained in `afterStatusCodes`, Ky will wait until the date, delay, or timestamp given in the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header has passed to retry the request. If `Retry-After` is missing, the non-standard [`RateLimit-Reset`](https://www.ietf.org/archive/id/draft-polli-ratelimit-headers-05.html#section-3.3) header is used in its place as a fallback. If the provided status code is not in the list, the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header will be ignored.
298298

299299
If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will use `maxRetryAfter`.
300300

source/types/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export type KyOptions = {
174174
175175
Network errors (e.g., DNS failures, connection refused, offline) are automatically retried for retriable methods. Only errors recognized as network errors are retried; other errors (e.g., programming bugs) are thrown immediately. Use `shouldRetry` to customize this behavior.
176176
177-
If the response provides an HTTP status contained in `afterStatusCodes`, Ky will wait until the date, timeout, or timestamp given in the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header has passed to retry the request. If `Retry-After` is missing, the non-standard [`RateLimit-Reset`](https://www.ietf.org/archive/id/draft-polli-ratelimit-headers-05.html#section-3.3) header is used in its place as a fallback. If the provided status code is not in the list, the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header will be ignored.
177+
If the response provides an HTTP status contained in `afterStatusCodes`, Ky will wait until the date, delay, or timestamp given in the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header has passed to retry the request. If `Retry-After` is missing, the non-standard [`RateLimit-Reset`](https://www.ietf.org/archive/id/draft-polli-ratelimit-headers-05.html#section-3.3) header is used in its place as a fallback. If the provided status code is not in the list, the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header will be ignored.
178178
179179
If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will use `maxRetryAfter`.
180180

test/retry.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,18 +2029,18 @@ test('totalTimeout with retryOnTimeout: true caps total time across retries', as
20292029

20302030
const customFetch: typeof fetch = async () => {
20312031
requestCount++;
2032-
// Each attempt takes 600ms, exceeding the 400ms per-attempt timeout
2033-
await delay(600);
2032+
// Each attempt takes longer than the per-attempt timeout, so every attempt times out.
2033+
await delay(300);
20342034
return new Response('ok');
20352035
};
20362036

20372037
await t.throwsAsync(
20382038
ky('https://example.com', {
20392039
fetch: customFetch,
2040-
timeout: 400,
2041-
totalTimeout: 1500,
2040+
timeout: 100,
2041+
totalTimeout: 1000,
20422042
retry: {
2043-
limit: 10,
2043+
limit: 30,
20442044
retryOnTimeout: true,
20452045
delay: () => 0,
20462046
},
@@ -2050,8 +2050,11 @@ test('totalTimeout with retryOnTimeout: true caps total time across retries', as
20502050
},
20512051
);
20522052

2053-
// Each attempt times out at ~400ms. Within 1500ms totalTimeout, 2-4 attempts fit.
2054-
t.true(requestCount >= 2 && requestCount <= 4);
2053+
// Each attempt times out at ~100ms, so many attempts fit within the 1000ms totalTimeout.
2054+
// The exact count is timing-dependent (slow CI runs fewer), so we only assert the invariant:
2055+
// it retried at least once, and totalTimeout stopped it well before the retry limit.
2056+
t.true(requestCount >= 2, `Expected at least 2 attempts, got ${requestCount}`);
2057+
t.true(requestCount < 30, `Expected totalTimeout to cap below the retry limit, got ${requestCount}`);
20552058
});
20562059

20572060
test('NetworkError wraps fetch network errors', async t => {

0 commit comments

Comments
 (0)