1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

请求失败等3s后再试

This commit is contained in:
程序员小墨 2022-07-29 19:20:25 +08:00
parent f3e47b16d0
commit e8e5f68c5b
4 changed files with 13 additions and 4 deletions

View File

@ -19,7 +19,10 @@ async function main() {
let result = await requestUtils.getApiResult(API_URL); let result = await requestUtils.getApiResult(API_URL);
if (result.code != 0) { 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); result = await requestUtils.getApiResult(API_URL);
if (result.ok != 1) { 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, "请求成功,但服务器处理失败,保存失败信息。");

View File

@ -19,7 +19,10 @@ async function main() {
let result = await requestUtils.getApiResult(API_URL); let result = await requestUtils.getApiResult(API_URL);
if (result.code != 0) { 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); result = await requestUtils.getApiResult(API_URL);
if (result.ok != 1) { 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, "请求成功,但服务器处理失败,保存失败信息。");

View File

@ -19,7 +19,10 @@ async function main() {
let result = await requestUtils.getApiResult(API_URL); let result = await requestUtils.getApiResult(API_URL);
if (result.ok != 1) { 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); result = await requestUtils.getApiResult(API_URL);
if (result.ok != 1) { 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, "请求成功,但服务器处理失败,保存失败信息。");

View File

@ -14,7 +14,7 @@ async function getApiResult(url) {
} else { } else {
// 请求失败 // 请求失败
console.log(`error is ${error}`); console.log(`error is ${error}`);
resolve("error"); resolve(null);
} }
}); });
}); });