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

Comments

@vissermc
Copy link

commented Oct 14, 2016

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

This comment has been minimized.

Copy link
Member

commented Oct 14, 2016

  • 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

This comment has been minimized.

Copy link
Author

commented Oct 17, 2016

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

This comment has been minimized.

Copy link
Author

commented Oct 17, 2016

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;
});
}

@TheCrow1213

This comment has been minimized.

Copy link

commented Oct 17, 2016

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

This comment has been minimized.

Copy link
Member

commented Oct 18, 2016

Fixed via 3fcf54f

@TheCrow1213

This comment has been minimized.

Copy link

commented Oct 18, 2016

Thanks @nickuraltsev :)

@jadelmir

This comment has been minimized.

Copy link

commented Mar 14, 2018

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

This comment has been minimized.

Copy link

commented May 6, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.