我有一个异步等待功能,该功能正在循环处理乱序的项目。完成之前,如何检查阵列中的每个项目!日志到控制台?因此,每次链接出现错误时,都应在与其关联的索引号之后记录错误。 例如:
0
此处出现错误https://test123.com/ergaergrhaerha0
1
2
3
此处出现错误https://test123.com/ergaergrhaerha3
...
完成!
processArray(ftJsonBySeqAssets);
async function processArray(arr) {
for (i in arr) {
console.log(i)
await https.get(arr[i].image_link, async (res) => {
await console.log(res.statusCode, arr[i].image_link)
if (res.statusCode === 404) {
console.log('ERROR HERE', arr[i].image_link)
audience.error.image_link.push(arr[i].image_link)
audience.error.count++
}
});
await https.get(arr[i].link, async (res) => {
await console.log(res.statusCode, arr[i].link)
if (res.statusCode === 404) {
console.log('ERROR HERE', arr[i].link)
audience.error.link.push(arr[i].link)
audience.error.count++
}
});
}
console.log('done!')
}
日志:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
done!
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
答案 0 :(得分:-1)
看起来no-cors
不会返回承诺,因此您必须自己构造一个,然后等待:
https.req