Skip to content

Commit 8b2aa82

Browse files
committed
Update the retry.fetch docs
1 parent 0df6264 commit 8b2aa82

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

docs/v3/errors-retrying.mdx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ export const taskWithFetchRetries = task({
106106
//if the Response is a 429 (too many requests), it will retry using the data from the response. A lot of good APIs send these headers.
107107
const headersResponse = await retry.fetch("http://my.host/test-headers", {
108108
retry: {
109-
"429": {
110-
strategy: "headers",
111-
limitHeader: "x-ratelimit-limit",
112-
remainingHeader: "x-ratelimit-remaining",
113-
resetHeader: "x-ratelimit-reset",
114-
resetFormat: "unix_timestamp_in_ms",
109+
byStatus: {
110+
"429": {
111+
strategy: "headers",
112+
limitHeader: "x-ratelimit-limit",
113+
remainingHeader: "x-ratelimit-remaining",
114+
resetHeader: "x-ratelimit-reset",
115+
resetFormat: "unix_timestamp_in_ms",
116+
},
115117
},
116118
},
117119
});
@@ -121,13 +123,15 @@ export const taskWithFetchRetries = task({
121123
//if the Response is a 500-599 (issue with the server you're calling), it will retry up to 10 times with exponential backoff
122124
const backoffResponse = await retry.fetch("http://my.host/test-backoff", {
123125
retry: {
124-
"500-599": {
125-
strategy: "backoff",
126-
maxAttempts: 10,
127-
factor: 2,
128-
minTimeoutInMs: 1_000,
129-
maxTimeoutInMs: 30_000,
130-
randomize: false,
126+
byStatus: {
127+
"500-599": {
128+
strategy: "backoff",
129+
maxAttempts: 10,
130+
factor: 2,
131+
minTimeoutInMs: 1_000,
132+
maxTimeoutInMs: 30_000,
133+
randomize: false,
134+
},
131135
},
132136
},
133137
});
@@ -136,9 +140,9 @@ export const taskWithFetchRetries = task({
136140

137141
//You can additionally specify a timeout. In this case if the response takes longer than 1 second, it will retry up to 5 times with exponential backoff
138142
const timeoutResponse = await retry.fetch("https://httpbin.org/delay/2", {
139-
timeout: {
140-
durationInMs: 1000,
141-
retry: {
143+
timeoutInMs: 1000,
144+
retry: {
145+
timeout: {
142146
maxAttempts: 5,
143147
factor: 1.8,
144148
minTimeoutInMs: 500,

0 commit comments

Comments
 (0)