From 8778ad53ab9f89bde64e491d9fe6f0c35869aafd 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?= Date: Thu, 2 Jan 2025 21:03:18 +0800 Subject: [PATCH] =?UTF-8?q?hotband=20=E8=AF=B7=E6=B1=82=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=B8=8D=E4=BF=9D=E5=AD=98=20origin-error=20=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=8B=20.json=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hotband/src/get_bilibili_hotband.js | 8 ++++++++ hotband/src/get_bilibili_rank.js | 8 ++++++++ hotband/src/get_weibo_hotband.js | 8 ++++++++ hotband/src/utils/requestUtils.js | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/hotband/src/get_bilibili_hotband.js b/hotband/src/get_bilibili_hotband.js index 7da0f90..1d4cb72 100644 --- a/hotband/src/get_bilibili_hotband.js +++ b/hotband/src/get_bilibili_hotband.js @@ -18,12 +18,20 @@ async function main() { let now = new Date(requestTimestamp + 8 * 3600 * 1000).toISOString(); let result = await requestUtils.getApiResult(API_URL); + if (result === undefined) { + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求失败"); + return; + } if (result.code != 0) { 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 === undefined) { + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "重试请求失败"); + return; + } if (result.ok != 1) { console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,保存失败信息。"); // ok 不为 1,那么久直接保存便于后续分析,不进行后续处理 diff --git a/hotband/src/get_bilibili_rank.js b/hotband/src/get_bilibili_rank.js index 01be364..60b7114 100644 --- a/hotband/src/get_bilibili_rank.js +++ b/hotband/src/get_bilibili_rank.js @@ -18,12 +18,20 @@ async function main() { let now = new Date(requestTimestamp + 8 * 3600 * 1000).toISOString(); let result = await requestUtils.getApiResult(API_URL); + if (result === undefined) { + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求失败"); + return; + } if (result.code != 0) { 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 === undefined) { + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "重试请求失败"); + return; + } if (result.ok != 1) { console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,保存失败信息。"); // ok 不为 1,那么久直接保存便于后续分析,不进行后续处理 diff --git a/hotband/src/get_weibo_hotband.js b/hotband/src/get_weibo_hotband.js index cd0fcee..b5bfbd7 100644 --- a/hotband/src/get_weibo_hotband.js +++ b/hotband/src/get_weibo_hotband.js @@ -18,12 +18,20 @@ async function main() { let now = new Date(requestTimestamp + 8 * 3600 * 1000).toISOString(); let result = await requestUtils.getApiResult(API_URL); + if (result === undefined) { + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求失败"); + return; + } if (result.ok != 1) { 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 === undefined) { + console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "重试请求失败"); + return; + } if (result.ok != 1) { console.log(new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), SUB_FOLDER, "请求成功,但服务器处理失败,保存失败信息。"); // ok 不为 1,那么就直接保存便于后续分析,不进行后续处理 diff --git a/hotband/src/utils/requestUtils.js b/hotband/src/utils/requestUtils.js index d2547df..807b310 100644 --- a/hotband/src/utils/requestUtils.js +++ b/hotband/src/utils/requestUtils.js @@ -14,7 +14,7 @@ async function getApiResult(url) { } else { // 请求失败 console.log(`error is ${error}`); - resolve({}); + resolve(undefined); } }); });