Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After successfully cancelling Axios, will the 'then' callback still execute? #6272

Open
liangliangGit opened this issue Mar 1, 2024 · 5 comments

Comments

@liangliangGit
Copy link

Describe the issue

The following is my code. After successfully canceling Axios, will the log (test then) in 'then' still be printed to the console? In other words, will 'then' still execute?
AXIOS.post(test`, data,{
cancelToken: cancelSource.cancelToken,
}).then(response => {

console.log("test then")
}).catch(error => {

})`

Example Code

No response

Expected behavior

No response

Axios Version

No response

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

@startjava
Copy link

https://axios-http.com/zh/docs/cancellation

now use signal: controller.signal.

cancelToken is old !

@liangliangGit
Copy link
Author

https://axios-http.com/zh/docs/cancellation

now use signal: controller.signal.

cancelToken is old !

Thank you for your response. I will proceed with the latest approach, but I am still curious about the answer to my previous question: will the 'then' be executed? @startjava

@liangliangGit
Copy link
Author

https://axios-http.com/zh/docs/cancellation

now use signal: controller.signal.

cancelToken is old !

Successfully cancelled Axios, but why did the 'then' continue to execute? Here is the code:
const controller = new AbortController();

axios.get('/foo/bar', {
signal: controller.signal
}).then(function(response) {
//...
});
controller.abort()

@startjava
Copy link

check response param about propperties

@DigitalBrainJS
Copy link
Collaborator

No, it won't. Cancellation in Axios, as in fetch, means promise rejection with a special error instance, so only the callback of the catch chain will be invoked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants