You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BREAKING-RELEASE: change default behavior so fetch-retry retries on FetchErrors of type system; add custom error handling option (#63)
* fetch-retry retries on FetchErrors of type system
* network timeout test mocked
* fix test
* fix function description
* make test fuzzy
* skip not mocked enotfound test since it is not stable
Copy file name to clipboardExpand all lines: README.md
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,8 @@ Without configuring any parameters, the retry behavior will be as follows:
24
24
- retry for 60s
25
25
- retry inital delay of 100ms with exponential backoff, configurable as a multiplier defaulting to 2
26
26
- retry only on 5xx response
27
+
- retry on all FetchError system errors
28
+
- see node-fetch error handling: https://github.com/node-fetch/node-fetch/blob/main/docs/ERROR-HANDLING.md
27
29
- socket timeout of 30s
28
30
```js
29
31
constfetch=require('@adobe/node-fetch-retry');
@@ -57,6 +59,7 @@ All the retry options are configurable and can be set in `retryOptions` in the `
57
59
|`retryInitialDelay`| Number | time in milliseconds to wait between retries |`NODE_FETCH_RETRY_INITIAL_WAIT`| 100 ms |
58
60
|`retryBackoff`| Number | backoff factor for wait time between retries |`NODE_FETCH_RETRY_BACKOFF`| 2.0 |
59
61
|`retryOnHttpResponse`| Function | a *function* determining whether to retry given the HTTP response | none | retry on all 5xx errors|
62
+
|`retryOnHttpError`| Function | a *function* determining whether to retry given the HTTP error exception thrown | none | retry on all `FetchError`'s of type `system`|
60
63
|`socketTimeout`| Number | time until socket timeout in milliseconds. _Note: if `socketTimeout` is >= `retryMaxDuration`, it will automatically adjust the socket timeout to be exactly half of the `retryMaxDuration`. To disable this feature, see `forceSocketTimeout` below_|`NODE_FETCH_RETRY_SOCKET_TIMEOUT`| 30000 ms |
61
64
|`forceSocketTimeout`| Boolean | If true, socket timeout will be forced to use `socketTimeout` property declared regardless of the `retryMaxDuration`. _Note: this feature was designed to help with unit testing and is not intended to be used in practice_|`NODE_FETCH_RETRY_FORCE_TIMEOUT`| false |
62
65
@@ -129,6 +132,20 @@ async main() {
129
132
});
130
133
}
131
134
```
135
+
This example shows how to retry on all HTTP errors thrown as an exception:
0 commit comments