re run auto chat when encounter errorunhandledRejection event

This commit is contained in:
geekgeekrun
2024-03-12 00:14:47 +08:00
parent 5b5287d6f3
commit 494702df0d
@@ -1,5 +1,5 @@
import DingtalkPlugin from '@geekgeekrun/dingtalk-plugin/index.mjs' 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 { import {
SyncHook, SyncHook,
AsyncSeriesHook AsyncSeriesHook
@@ -22,7 +22,7 @@ const AUTO_CHAT_ERROR_EXIT_CODE = {
LOGIN_STATUS_INVALID: 82 LOGIN_STATUS_INVALID: 82
} }
;(async () => { const main = async () => {
if (!bossCookies?.length) { if (!bossCookies?.length) {
console.error('There is no cookies. You can save a copy with EditThisCookie extension.') console.error('There is no cookies. You can save a copy with EditThisCookie extension.')
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.COOKIE_INVALID) process.exit(AUTO_CHAT_ERROR_EXIT_CODE.COOKIE_INVALID)
@@ -42,7 +42,6 @@ const AUTO_CHAT_ERROR_EXIT_CODE = {
try { try {
await mainLoop(hooks) await mainLoop(hooks)
} catch (err) { } catch (err) {
console.log(err)
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) { if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID) process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID)
break break
@@ -50,4 +49,23 @@ const AUTO_CHAT_ERROR_EXIT_CODE = {
await sleep(3000) await sleep(3000)
} }
} }
})() }
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()
});