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

Interceptors? How can I make the interceptors inherit the hook? #1130

Closed
ssttm169 opened this issue Oct 13, 2017 · 1 comment
Closed

Interceptors? How can I make the interceptors inherit the hook? #1130

ssttm169 opened this issue Oct 13, 2017 · 1 comment

Comments

@ssttm169
Copy link

ssttm169 commented Oct 13, 2017

Hi everybody, I have a problem about the Interceptors. sometime when I'm fetching api, it will timeout, because I set axios.defaults.timeout = 6000. The problem is I want to fetch again and bring something I have already coded. just take a look at these code below:

this action sometime would timeout.

this.$axios.get('http://www.google.com/this-page-doesnt-exist.html').then(function (response) {
  console.log('Yes, I have a iphone X.');
  //....or a lot of code....
})

so I use interceptors to fetch again, but I have a hook above console.log('Yes, I have a iphone X.'), How can I make interceptors inherit the hook?

axios.interceptors.response.use(function(response){
  return response;
  }, function(error){
  if(error.code == 'ECONNABORTED' && error.message.indexOf('timeout')!=-1){
      axios({
        url:error.config.url,
        method:error.config.method,
        params:error.config.params,
        data:error.config.data || ''
      }).then(function (response) {
        console.log('Do you have an iPhone?')
        //it should print Yes, I have a iphone X.
      });
  }
 return Promise.reject(error);
})
@ssttm169 ssttm169 changed the title Interceptors? How can I fetch again and bring something I have already done? Interceptors? How can I make the interceptors inherit the hook? Oct 13, 2017
@ssttm169
Copy link
Author

The solution is here Adding Retry Parameter

@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

1 participant