TypeError: Cannot read property 'cancelToken' of undefined
itsazzad opened this issue ยท 11 comments
const middlewareConfig = {
interceptors: {
request: [
{
success: function ({getState, dispatch, getSourceAction}, req) {
console.error(1, req);
},
error: function ({getState, dispatch, getSourceAction}, error) {
console.error(2, error);
}
}
],
response: [
{
success: function ({getState, dispatch, getSourceAction}, req) {
console.error(3, req);
},
error: function ({getState, dispatch, getSourceAction}, error) {
console.error(4, error);
}
}
]
}
};
const middleware = [
multiClientMiddleware(clients, middlewareConfig),
routerMiddleware(history)
];
export default createStore(
reducers,
composeEnhancers(
applyMiddleware(...middleware)
)
)
TypeError: Cannot read property 'cancelToken' of undefined
at throwIfCancellationRequested (index.js?v=:72)
at dispatchRequest (index.js?v=:84)
+1๏ผI met too, @liyuanqiu, Have you solved it?
Look the Comments
axios.interceptors.request.use(function(config) {
console.log('request => config ====================================');
console.log(config);
console.log('request => config ====================================');
// if u add new Chainable promise or other interceptor
// You have to return `config` inside of a rquest
// otherwise u will get a very confusing error
// and spend sometime to debug it.
return config;
}, function(error) {
return Promise.reject(error);
});
If you write API.interceptors.request.use(config => { console.log(config) return config })
not forget return config
@vuchan you are right after return it's working perfectly. Below is my working code,
axiosInstance.interceptors.request.use((request) => {
this.setState({ showSpinner: true});
return requestHandler(request);
}, (error) => {
console.log('Interceptor error', error);
this.setState({ showSpinner: false});
return Promise.reject(error);
});
axiosInstance.interceptors.response.use((response) => {
this.setState({ showSpinner: false});
return successHandler(response);
}, (error) => {
this.setState({ showSpinner: false});
return errorHandler(error);
});
Config should be returned at the end
If you write
API.interceptors.request.use(config => { console.log(config) return config })
not forgetreturn config
thanks, a lot.
Look the Comments
axios.interceptors.request.use(function(config) { console.log('request => config ===================================='); console.log(config); console.log('request => config ===================================='); // if u add new Chainable promise or other interceptor // You have to return `config` inside of a rquest // otherwise u will get a very confusing error // and spend sometime to debug it. return config; }, function(error) { return Promise.reject(error); });
this saved my day. thanks :)
hi
thanks,that's right ! bro