Cancelling group by using "axios.default.cancelToken = ..." causes "config.cancelToken.throwIfRequested"
See original GitHub issue#### Summary
I am running axios requests in tests and when the test logic is complete I want to cancel all active requests (which are not related to the logic of the test). This is my init code:
let CancelToken = axios.CancelToken;
let axiosSource = CancelToken.source();
export const axiosCancel = axiosSource.cancel;
axios.defaults.cancelToken = axiosSource.token;
and then, (using mocha) I run cancel like this:
afterEach(() => {
axiosCancel();
});
When axiosCancel()
is run I get this error in the stack:
Error: TypeError: config.cancelToken.throwIfRequested is not a function
at Error (native)
at /Users/Ben_Katz/Git/wix/user-manager/src/client/actions/fetchUserByDomain.ts:34:13 } with Error: TypeError: config.cancelToken.throwIfRequested is not a function
at Error (native)
at /Users/Ben_Katz/Git/wix/user-manager/src/client/actions/fetchUserByDomain.ts:34:13 +0ms
I don’t know if this is not working because it’s not supposed to work that way but the error gives me no information and as far as I can tell it’s a bug. #### Context
- axios version: v0.16.3*
- Environment: node v6.10.4, MacOs sierra*
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Cancelling group by using "axios.default ... - Bountysource
Cancelling group by using "axios.default.cancelToken = ..." causes "config.cancelToken.throwIfRequested" ... I am running axios requests in tests ...
Read more >Axios cancel token cancelling request before even called
I hope you should throttle your requests instead of canceling the request. Could you please try the following if throttle does not suit...
Read more >Cancellation | Axios Docs
CancelToken deprecated. You can also cancel a request using a CancelToken. The axios cancel token API is based on the withdrawn cancelable promises...
Read more >How to use the axios.CancelToken function in axios - Snyk
CancelToken examples, based on popular ways it is used in public projects. ... Cancellation) => { let cancellable = true return { cancelToken:...
Read more >Axios Cancel Request - Morioh
The Axios global has a CancelToken object that can create a cancel token for ... passing a reason for the cancellation, you can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A fast workaround for this issue:
@Bnaya got it, thanks 😃