- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 axios-retry
模块向我的 api 调用添加重试。为了测试我正在使用 mockoon
macosx 客户端。我在 mockoon
中设置了端点以始终返回 502
响应。以便我可以测试重试。
import axios from "axios";
import axiosRetry from 'axios-retry';
async function sendRequest(method): Promise<any> {
try {
// return 502 after 100ms
let url = `http://localhost:3000/answer`
axiosRetry(axios, {
retries: 3
});
const response = await axios[method](url);
console.log('api call completed');
return response;
} catch (error) {
console.log('api call error: ', error);
throw error;
}
}
(async () => {
const response = await sendRequest('get')
})()
这里的问题是,axios.get
没有完成执行。因此,它不会记录 api 调用错误
或 api 调用已完成
消息。任何帮助将不胜感激。
最佳答案
axiosRetry
不适用于 axios 0.19.0
(当前的 axios 版本):https://github.com/softonic/axios-retry#note
使用通用的异步重试函数,例如
async function retry<T>(fn: () => Promise<T>, n: number): Promise<T> {
let lastError: any;
for (let index = 0; index < n; index++) {
try {
return await fn();
}
catch (e) {
lastError = e;
}
}
throw lastError;
}
// use
const response = await retry(() => axios[method](url), 3);
关于javascript - 如何使用axios客户端重试5xx错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59366972/
我住在荷兰,货币是用逗号 (,) 而不是点 (.)即 14.95 的 feeds 被解释为数字而不是 14.95 欧元 有没有可以解决这个问题的LINUX命令(sed?)?所以14.95变成了14,9
我想问: 我有两个表employee,其中包含字段ID、Fullname、email...和表task 包含字段 name_task、list_employee... 使用字段list_employe
请看下面的测试数据。我想获取 avgtime (=timeonsite/visits) 并在 mysql 中显示为“xx:xx:xx”结果。我怎样才能得到它? SET FOREIGN_KEY_CHEC
我必须处理一个大文件(几 MB)并从中删除带有时间标记的注释。一个例子: blablabla 12:10:40 I want to remove this blablabla some more e
所以我有这些数据直接从 iTunes 复制/粘贴: Excel 具有“XX:XX:00”格式,即“hh:mm:ss”,但您可以想象,它更像“mm:ss:00”。音乐时间不长! 由于这不是直接的单元格格
我有一个对象列表,我想使用 Option.Numero_Reference 属性对其进行排序。 Numero_reference 是一个 xx.xx.xx 格式的字符串 有没有办法按 xx 组排序?
我正在尝试部署 nginx - ingress kubectl run nginx --image=nginx kubectl get pod NAME
我有一个日期“2014-07-02 20:57:38 +0000”,我想将它的格式设置为“今天晚上 8:57”。我希望如果一个字符串是昨天,则将其显示为“昨天上午 9:00”。如果既不是今天也不是昨天
目前我使用的是Apache http components client V4.3.5。在我的例子中,我可以上传小文件(1kb),但是当我运行代码并得到异常“org.apache.http.NoHtt
我在 Linux (RHEL 7) 中运行 HTTPS 服务器。我一启动服务器就收到以下错误。 2019/09/04 15:46:16 http: TLS handshake error from x
我正在参加 CTF 挑战赛,该挑战赛有一个链接,如下所示:46.XXX.XX.XX:8008/ 如果我打开该页面中的开发者工具,我可以找到一个小程序,其属性代码值为“mPage.class”
你好 我想每隔 X 小时在我的程序中运行一个方法,该怎么做?我正在谷歌搜索,但什么也没有:/ 最佳答案 你可以考虑Quartz . 它是在 java 中运行的某种 cron。不过我承认,如果您只想安排
我正在尝试检查 NSString 是否为特定格式。 日:日:日。我在想 NSRegularExpression。有点像 /^(\d)\d:\d\d:\d\d)$/? 最佳答案 你有没有试过这样的事情:
我收到错误 git 存储库的 RSA 主机 key 不在已知主机列表中。当我使用存储库 URL 作为我的 git 克隆 URL 运行 jenkins 作业时。 我尝试在运行作业的主机中克隆相同的存储库
我有一个计数器,每 1 秒计数一次,并将 1 添加到 int。 问题 如何格式化我的字符串,使计数器看起来像这样: 00:01:23 代替: 123 我尝试过的事情 到目前为止我尝试过的事情: for
ERROR 2003 (HY000): Can't connect to MySQL server on 'xx.xx.xx.xx.' (60) 我在尝试远程连接到此服务器时收到此错误。我最近硬重启了
我正在尝试将一些数据从客户端浏览器插入到 AWS 服务器上的 MySQL 数据库。 该代码在 godaddy 上运行,因此看起来像是权限/安全问题。 $servername = "xx.xx.xx.x
我想知道是否有标准方法可以以“UTC+XX:XX”或“UTC-XX:XX”格式返回设备的当前时区? 基于格式化 NSDate 我知道可以在“ZZZZ”的帮助下获得当前时区,它给出“GMT-08:00”
我的 JVM 有 -server 选项,我相信它使 JVM 能够使用 C2 编译器,这意味着用于服务器应用程序,这些应用程序往往比客户端应用程序运行时间更长。但是,GRAAL JIT(由 -XX:+U
public void colortemperatureJSliderStateChanged(ChangeEvent event) { fahrenheitdegree = colortemp
我是一名优秀的程序员,十分优秀!