axios的超时是在response中处理的,所以要在response中添加拦截器:

axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
var config = err.config;
// If config does not exist or the retry option is not set, reject
if(!config || !config.retry) return Promise.reject(err); // Set the variable for keeping track of the retry count
config.__retryCount = config.__retryCount || 0; // Check if we've maxed out the total number of retries
if(config.__retryCount >= config.retry) {
// Reject with the error
return Promise.reject(err);
} // Increase the retry count
config.__retryCount += 1; // Create new promise to handle exponential backoff
var backoff = new Promise(function(resolve) {
setTimeout(function() {
resolve();
}, config.retryDelay || 1);
}); // Return the promise in which recalls axios to retry the request
return backoff.then(function() {
return axios(config);
});
});

使用:

axios.get('/some/endpoint', { retry: 5, retryDelay: 1000 })
.then(function(res) {
console.log('success', res.data);
})
.catch(function(err) {
console.log('failed', err);
});

出处:https://github.com/axios/axios/issues/164#issuecomment-327837467

最新文章

  1. css样式之超出隐藏
  2. Looper.prepare()和Looper.loop()
  3. IO(五)----打印流
  4. Es6 学习笔记
  5. js中this的问题
  6. linux常见进程与内核线程
  7. Android View.onMeasure方法的理解
  8. Git超级实用使用教程
  9. WPF中的ControlTemplate(控件模板)(转)
  10. asp实现关键词不区分大小写搜索并高亮显示
  11. 使用curl获取网站的http的状态码
  12. (转)Android中截取当前屏幕图片
  13. 红豆带你从零学C#系列—Visual Studio工具介绍、下载和安装
  14. Ubuntu 12.04 Android2.2源码make** /classes-full-debug.jar Error 41错误解决
  15. POJ 2778 DNA Sequence(AC自动机+矩阵快速幂)
  16. android奋战的一周
  17. 【Android 系统开发】 Android 系统启动流程简介
  18. Kafka-python 客户端导致的 cpu 使用过高,且无法消费消息的问题
  19. oracle的读写分离实现
  20. 怎样建立你自己的MASM导入库

热门文章

  1. PHP-入门指引1
  2. (数据科学学习手札36)tensorflow实现MLP
  3. itchat和matplotlib的结合使用爬取微信信息
  4. java web相对路径和绝对路径总结
  5. Linux:如何获取打开文件和文件描述符数量
  6. Android ANR 分析
  7. 让webapi支持CORS,可以跨域访问
  8. python接口自动化: CAS系统验证,自动完成登录并获取token,遇到302请求重定向设置(requests模块 allow_redirects=False)即可
  9. python3.x 编码问题
  10. kubernetes(k8s) 集群