I've got a series of pending requests lined up
const requests = [];
requests.push(axios.post('/request1', {moo:1});
requests.push(axios.post('/request2', {moo:2});
requests.push(axios.post('/request3', {moo:3});
Promise.all(requests).then((reponse) => {
debugger;
}).catch((err) => {
debugger;
});
If any one of them fails, I want to cancel all the requests. But currently, even if one fails, the next request still goes through.
I attempted some cancellation code, but the subsequent request still gets triggered
const requests = [];
const source = axios.CancelToken.source();
const cancelToken = source.token;
requests.push(axios.post('/request1', {moo:1}, {cancelToken} );
requests.push(axios.post('/request2', {moo:2}, {cancelToken} );
requests.push(axios.post('/request3', {moo:3}, {cancelToken} );
Promise.all(requests).then((reponse) => {
debugger;
}).catch((err) => {
source.cancel("Request canceled");
debugger;
});