From a850753f49fe7a7c394ae240a430f082eb52c1fe Mon Sep 17 00:00:00 2001 From: wong2 Date: Fri, 15 Dec 2023 13:25:15 +0800 Subject: [PATCH] Handle initializeBot error --- src/app/bots/abstract-bot.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/app/bots/abstract-bot.ts b/src/app/bots/abstract-bot.ts index 4707179d..6842feb8 100644 --- a/src/app/bots/abstract-bot.ts +++ b/src/app/bots/abstract-bot.ts @@ -102,18 +102,26 @@ class DummyBot extends AbstractBot { export abstract class AsyncAbstractBot extends AbstractBot { #bot: AbstractBot + #initializeError?: Error constructor() { super() this.#bot = new DummyBot() - this.initializeBot().then((bot) => { - this.#bot = bot - }) + this.initializeBot() + .then((bot) => { + this.#bot = bot + }) + .catch((err) => { + this.#initializeError = err + }) } abstract initializeBot(): Promise doSendMessage(params: SendMessageParams) { + if (this.#bot instanceof DummyBot && this.#initializeError) { + throw this.#initializeError + } return this.#bot.doSendMessage(params) }