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
Setting the `timeout` property in an axios call handles **response** related timeouts.
12
+
13
+
In some cases (e.g. network connection becomes unavailable) an axios call would benefit from cancelling the **connection** early. Without cancellation, the axios call can hang until the parent code/stack times out (might be a few minutes in a server-side applications).
14
+
15
+
To terminate an axios call you can use following methods:
16
+
-`signal`
17
+
-`cancelToken` (deprecated)
18
+
19
+
Combining `timeout` and cancellation method (e.g. `signal`) should cover **response** related timeouts AND **connection** related timeouts.
20
+
21
+
### `signal`: AbortController
10
22
11
23
Starting from `v0.22.0` Axios supports [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to cancel requests in fetch API way:
12
24
@@ -22,7 +34,32 @@ axios.get('/foo/bar', {
22
34
controller.abort()
23
35
```
24
36
25
-
## CancelToken `deprecated`
37
+
Example with a timeout using latest [`AbortSignal.timeout()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout) API [nodejs 17.3+]:
38
+
```js
39
+
axios.get('/foo/bar', {
40
+
signal:AbortSignal.timeout(5000) //Aborts request after 5 seconds
0 commit comments