From 95a31d1521af481db57c3d972604a61587a7dce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=81=97=E5=BF=98=E7=9A=84=E8=AE=B0=E5=BF=86?= <32097237+YIWANG-sketch@users.noreply.github.com> Date: Sun, 8 Sep 2024 17:37:57 +0800 Subject: [PATCH] response timeout to avoid termination --- provider.mjs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/provider.mjs b/provider.mjs index d9708f3..222ac5d 100644 --- a/provider.mjs +++ b/provider.mjs @@ -48,6 +48,7 @@ class YouProvider { console.log(`切换到${this.currentMode}模式,将在${this.switchThreshold}次请求后再次切换`); } + async init(config) { console.log(`本项目依赖Chrome或Edge浏览器,请勿关闭弹出的浏览器窗口。如果出现错误请检查是否已安装Chrome或Edge浏览器。`); @@ -978,12 +979,10 @@ class YouProvider { await page.goto(`https://you.com/search?q=&fromSearchBar=true&tbm=youchat&chatMode=custom`, {waitUntil: "domcontentloaded"}); } - responseTimeout = setTimeout(async () => { + responseTimeout = setTimeout(() => { if (!responseStarted) { console.log("40秒内没有收到响应,终止请求"); - isEnding = true; - await cleanup(); - emitter.emit("error", new Error("No response received within 40 seconds, request terminated")); + emitter.emit("warning", new Error("No response received within 40 seconds")); } }, 40000); @@ -993,11 +992,6 @@ class YouProvider { } catch (error) { console.error("评估过程中出错:", error); emitter.emit("error", error); - return { - completion: emitter, - cancel: () => { - } - }; } const cancel = () => {