From e8e5f68c5b983e7883ff583490e2bf0e27ce9292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Fri, 29 Jul 2022 19:20:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B1=E8=B4=A5=E7=AD=893s?= =?UTF-8?q?=E5=90=8E=E5=86=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/get_bilibili_hotband.js | 5 ++++- src/get_bilibili_rank.js | 5 ++++- src/get_weibo_hotband.js | 5 ++++- src/utils/requestUtils.js | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/get_bilibili_hotband.js b/src/get_bilibili_hotband.js index 2a38c57..7da0f90 100644 --- a/src/get_bilibili_hotband.js +++ b/src/get_bilibili_hotband.js @@ -19,7 +19,10 @@ async function main() { let result = await requestUtils.getApiResult(API_URL); if (result.code != 0) { - console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,正在重试。"); + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,等待3s后重试。"); + await new Promise((resolve) => { + setTimeout(resolve, 3000); // 等待3秒 + }); result = await requestUtils.getApiResult(API_URL); if (result.ok != 1) { console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,保存失败信息。"); diff --git a/src/get_bilibili_rank.js b/src/get_bilibili_rank.js index dec154b..01be364 100644 --- a/src/get_bilibili_rank.js +++ b/src/get_bilibili_rank.js @@ -19,7 +19,10 @@ async function main() { let result = await requestUtils.getApiResult(API_URL); if (result.code != 0) { - console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,正在重试。"); + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,等待3s后重试。"); + await new Promise((resolve) => { + setTimeout(resolve, 3000); // 等待3秒 + }); result = await requestUtils.getApiResult(API_URL); if (result.ok != 1) { console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,保存失败信息。"); diff --git a/src/get_weibo_hotband.js b/src/get_weibo_hotband.js index cb08c35..bbe9d5a 100644 --- a/src/get_weibo_hotband.js +++ b/src/get_weibo_hotband.js @@ -19,7 +19,10 @@ async function main() { let result = await requestUtils.getApiResult(API_URL); if (result.ok != 1) { - console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,正在重试。"); + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,等待3s后重试。"); + await new Promise((resolve) => { + setTimeout(resolve, 3000); // 等待3秒 + }); result = await requestUtils.getApiResult(API_URL); if (result.ok != 1) { console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,保存失败信息。"); diff --git a/src/utils/requestUtils.js b/src/utils/requestUtils.js index ef37af4..6eab7d1 100644 --- a/src/utils/requestUtils.js +++ b/src/utils/requestUtils.js @@ -14,7 +14,7 @@ async function getApiResult(url) { } else { // 请求失败 console.log(`error is ${error}`); - resolve("error"); + resolve(null); } }); });