【发布时间】:2021-11-24 01:11:08
【问题描述】:
最近由于某种未知原因,我开始在控制台中看到常规错误。像这样:
(node:147) UnhandledPromiseRejectionWarning: Error: timeout of 1000ms exceeded
at createError (/home/runner/ricebot/node_modules/axios/lib/core/createError.js:16:15)
at RedirectableRequest.handleRequestTimeout (/home/runner/ricebot/node_modules/axios/lib/adapters/http.js:280:16)
at RedirectableRequest.emit (events.js:314:20)
at RedirectableRequest.EventEmitter.emit (domain.js:483:12)
at Timeout._onTimeout (/home/runner/ricebot/node_modules/follow-redirects/index.js:166:12)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
它有时也会使我的机器人的延迟达到 30000 毫秒。
我的有趣命令中只有 Axios 部分,这是其中之一(但它仍然可以正常工作,只是记录错误):
const url = 'https://no-api-key.com/api/v2/animals/cat';
let image;
let fact;
try {
const { data } = await axios.get(url);
console.log(data);
image = data.image;
fact = data.fact;
} catch (e) {
console.log(e)
return message.channel.send('An error occured, please try again!');
}
这不是过去的事情。
【问题讨论】:
-
好像axios无法获取你的url
-
@ChristophBlüm 它明白了,axios 部分工作
-
@8less 请您提供更多代码,因为您正在使用 await 您在一个函数中,
console.log(data);没有显示什么? -
@Saren 它记录了它应该记录的所有内容:{ 事实:'迪士尼乐园“雇佣”了近 200 只猫。',图片:'no-api-key.com/image/cat/95147.png'}
-
也许尝试在之后对其进行解构?
const a = await axios.get(url); const { data } = a
标签: javascript node.js axios discord.js bots