From 494702df0d9948afe641635e5c4c621be35bc713 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Tue, 12 Mar 2024 00:14:47 +0800 Subject: [PATCH] =?UTF-8?q?re=20run=20auto=20chat=20when=20encounter=20`er?= =?UTF-8?q?ror`=E3=80=81`unhandledRejection`=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index.mjs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs b/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs index 4a33475..ba1a2b4 100644 --- a/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs +++ b/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs @@ -1,5 +1,5 @@ import DingtalkPlugin from '@geekgeekrun/dingtalk-plugin/index.mjs' -import { mainLoop } from '@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs' +import { mainLoop, closeBrowserWindow } from '@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs' import { SyncHook, AsyncSeriesHook @@ -22,7 +22,7 @@ const AUTO_CHAT_ERROR_EXIT_CODE = { LOGIN_STATUS_INVALID: 82 } -;(async () => { +const main = async () => { if (!bossCookies?.length) { console.error('There is no cookies. You can save a copy with EditThisCookie extension.') process.exit(AUTO_CHAT_ERROR_EXIT_CODE.COOKIE_INVALID) @@ -42,7 +42,6 @@ const AUTO_CHAT_ERROR_EXIT_CODE = { try { await mainLoop(hooks) } catch (err) { - console.log(err) if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) { process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID) break @@ -50,4 +49,23 @@ const AUTO_CHAT_ERROR_EXIT_CODE = { await sleep(3000) } } -})() \ No newline at end of file +} +main() + +process.on('error', async (error) => { + closeBrowserWindow() + console.error('error') + console.error(error) + await sleep(3000) + + main() +}) + +process.on('unhandledRejection', async (reason, promise) => { + closeBrowserWindow() + console.error('unhandledRejection') + console.error(reason, promise) + await sleep(3000) + + main() +}); \ No newline at end of file