Open itsazzad opened 6 years ago
@itsazzad I met this problem too, have you got some solutions?
+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);
});
@Vuchan That's right, you must return req/error in those callback functions.
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