Source: Internet
Author: User

Tags: intercept axios reject efault default HTTP turn the + =

Axios call interface processing method after timeout request
Sets the global number of requests, the gap of the request Axios.defaults.retry = 2;axios.defaults.retrydelay = 1000;//HTTP response    Interceptor Axios.interceptors.response.use (response=>{//console.log (' After request response ');    Const RES =, code = res.error_code, msg = res.message; if (code = = 0| |    Code = = 1) {//Success return res;      }else if (code==-4) {console.log (msg);    Store.commit (' Updataloginflag ', false);    }else{Console.log (msg);  }}, (Err) = {//Return status code not to 200 error handling const;  Const Status=err.response.status;    Switch (status) {//case 500:router.push ({name: ' $ '});  Case 403:router.push ({name: ' 403 '});  } var config = err.config;  If the configuration does not exist, or if the retry option is not set, the IF (!config | |!config.retry) return Promise.reject (err) is rejected; Set a variable for tracking retry count Config.__retrycount = Config.__retrycount | |  0;  if (Config.__retrycount >= config.retry) {return promise.reject (err);  } Config.__retrycount + = 1; Create a new request to handle callback var Backoff = new Promise (functiOn (resolve) {setTimeout (function () {resolve (); }, Config.retrydelay | |  1);  });    Axios will re-request return Backoff.then (function () {config.baseurl= ";  return Axios (config); });});


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: