Skip to content

Commit

Permalink
Handle initializeBot error
Browse files Browse the repository at this point in the history
  • Loading branch information
wong2 committed Dec 15, 2023
1 parent ce11151 commit a850753
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/app/bots/abstract-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractBot>

doSendMessage(params: SendMessageParams) {
if (this.#bot instanceof DummyBot && this.#initializeError) {
throw this.#initializeError
}
return this.#bot.doSendMessage(params)
}

Expand Down

0 comments on commit a850753

Please sign in to comment.