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
Copy file name to clipboardExpand all lines: docs/sdk/api/sdkMiddlewareHttp.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ The HTTP middleware can run in either a browser or Node.js environment. For Node
40
40
11.`maxDelay`_(Number)_: The maximum duration (milliseconds) to wait before retrying, useful if the delay time grew exponentially more than reasonable
41
41
12.`fetch`_(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function
42
42
13.`timeout`_(Number)_: Request/response timeout in ms. Must have globally available or passed in `AbortController`
43
-
14.`AbortController` (_AbortController_): An`AbortController` instance. Could be [abort-controller](https://www.npmjs.com/package/abort-controller) or globally available one.
43
+
14.`abortController` or `getAbortController` depending on you chose to handle the timeout (_abortController_): This property accepts the`AbortController` instance. Could be [abort-controller](https://www.npmjs.com/package/abort-controller) or globally available one.
44
44
45
45
#### Retrying requests
46
46
@@ -79,6 +79,36 @@ const client = createClient({
79
79
})
80
80
```
81
81
82
+
## `abortController` | `getAbortController`
83
+
84
+
This is used to signal the retry module to retry the request in an event of a request timeout or service outage.
85
+
86
+
#### Usage example
87
+
88
+
```js
89
+
// Use default options
90
+
consthttpMiddleware=createHttpMiddleware({
91
+
host: testHost,
92
+
timeout:1000, // time out after 1s
93
+
fetch,
94
+
abortController:newAbortController(),
95
+
})
96
+
```
97
+
98
+
Note however the slight difference in usage of the `getAbortController` property of the http middleware.
99
+
100
+
```js
101
+
// Use default options
102
+
consthttpMiddleware=createHttpMiddleware({
103
+
host: testHost,
104
+
timeout:1000, // time out after 1s
105
+
fetch,
106
+
getAbortController: () =>newAbortController(),
107
+
})
108
+
```
109
+
110
+
This is to ensure that a new instance of the AbortController is always created and is independent of each other. Unlike the former (abortController) which only creates a single abortController instance for the middleware, in this very case, if a single request times out, it will propagate to all other http requests that is using the `AbortController` instance. This is useful when a bunch of sent out requests needs to timeout if at least one within the bunch times out.
111
+
82
112
## `getErrorByCode(code)`
83
113
84
114
Returns a [custom error type](/sdk/Glossary.md#httperrortype) given its status _code_.
0 commit comments