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

cancelling cancelToken on request that is already finished gives error #482

Closed
vissermc opened this issue Oct 14, 2016 · 8 comments
Closed

Comments

@vissermc
Copy link

there should be an easy mechanism to have 'overwrite' a request with a new one. Currently this is not possible. Also, it's not clear whether a cancelToken can be 'recycled', or whether a new one should be generated on every request

if (cancelToken) cancelToken.cancel();
cancelToken = axios.CancelToken.source();
axios.get(...

@nickuraltsev
Copy link
Member

  • What error do you get? Also, could you please provide a code snippet that reproduces the issue?
  • I'm not sure I understand what you mean by "overwriting" requests.
  • You should use different tokens for different requests unless you need to be able to cancel multiple requests as a group.

@vissermc
Copy link
Author

Code snippet:

Uncaught (in promise) TypeError: Cannot read property 'abort' of null(…)onCanceled
if (config.cancelToken) {
// Handle cancellation
config.cancelToken.promise.then(function onCanceled(cancel) {
request.abort(); <-- here
reject(cancel);
// Clean up request
request = null;
});
}

@vissermc
Copy link
Author

When calling this function twice, I get:

Error: Uncaught (in promise) TypeError: Cannot read property 'abort' of null(…)onCanceled

if (config.cancelToken) {
// Handle cancellation
config.cancelToken.promise.then(function onCanceled(cancel) {
request.abort(); <-- HERE
reject(cancel);
// Clean up request
request = null;
});
}

@cryptic-mystic
Copy link

Can confirm. Looks like lines adapters/http.js:191 and adapters/http.js:159 require null checks. For a method that sets the request var to null in several non-edge-cases, I'm surprised the check isn't in there.

@nickuraltsev
Copy link
Member

Fixed via 3fcf54f

@cryptic-mystic
Copy link

Thanks @nickuraltsev :)

@jadelmir
Copy link

I am getting an error while doing get request using axios
TypeError: Cannot read property 'cancelToken' of undefined
what is that and how could deal with it

@palakvasani
Copy link

Hello,

I am facing same error as mentioned by jadelmir. Please let me know if anyone has fixed for it. I am using Laravel 5.3 and implements Vue.js to build a chat application.

image

dispatchRequest.js?91bc:14 Uncaught (in promise) TypeError: Cannot read property 'cancelToken' of undefined at throwIfCancellationRequested (eval at <anonymous> (app.js:192), <anonymous>:14:14) at dispatchRequest (eval at <anonymous> (app.js:192), <anonymous>:26:3)
`
My app.js file looks like this

require('./bootstrap');



Vue.component('chat-messages', require('./components/ChatMessages.vue'));
Vue.component('chat-form', require('./components/ChatForm.vue'));


const app = new Vue({
    el: '#main',

    data: {
        messages: []
    },

    created() {
        this.fetchMessages();
		Echo.private('chat')
		.listen('MessageSent', (e) => {
			this.messages.push({
			  message: e.message.message,
			  user: e.user
			});
		  });
    },
	


    methods: {
        fetchMessages() {
            axios.get('/messages').then(response => {
                this.messages = response.data;
            });
        },

        addMessage(message) {
            this.messages.push(message);

            axios.post('/messages', message).then(response => {
              console.log(response.data);
            });
        }
    }
});

Regards,
Palak

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants