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

TypeError: Cannot read property 'cancelToken' of undefined #83

Open
itsazzad opened this issue Apr 23, 2018 · 11 comments
Open

TypeError: Cannot read property 'cancelToken' of undefined #83

itsazzad opened this issue Apr 23, 2018 · 11 comments

Comments

@itsazzad
Copy link

itsazzad commented Apr 23, 2018

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)

screen shot 2018-04-23 at 3 17 55 pm

screen shot 2018-04-23 at 3 19 33 pm

screen shot 2018-04-23 at 3 21 42 pm

screen shot 2018-04-23 at 3 23 48 pm

@liyuanqiu
Copy link

@itsazzad
I met this problem too, have you got some solutions?

@givingwu
Copy link

+1,I met too, @liyuanqiu, Have you solved it?

@givingwu
Copy link

givingwu commented Jul 24, 2018

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

@liyuanqiu
Copy link

@vuchan
That's right, you must return req/error in those callback functions.

@Wuruiyang
Copy link

If you write API.interceptors.request.use(config => { console.log(config) return config }) not forget return config

@MartinJesu
Copy link

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

@oceceli
Copy link

oceceli commented Feb 16, 2020

Config should be returned at the end

@hardeath950
Copy link

If you write API.interceptors.request.use(config => { console.log(config) return config }) not forget return config

thanks, a lot.

@premk92
Copy link

premk92 commented Jul 30, 2021

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 :)

@GunelYusuf
Copy link

hi

@Janeonly300
Copy link

thanks,that's right ! bro

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

10 participants