Skip to content

Commit

Permalink
fix: do not crash bot.stop if starting failed (#577)
Browse files Browse the repository at this point in the history
* fix: do not crash bot.stop if starting failed

* fix: start again
  • Loading branch information
KnorpelSenf authored May 10, 2024
1 parent 5b94f2e commit 45d71b6
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,19 +427,25 @@ a known bot info object.",
await Promise.all(setup);
debug("Simple long polling already running!");
return;
} else {
this.pollingRunning = true;
this.pollingAbortController = new AbortController();
}
setup.push(withRetries(async () => {
await this.api.deleteWebhook({
drop_pending_updates: options?.drop_pending_updates,
}, this.pollingAbortController?.signal);
}, this.pollingAbortController?.signal));
await Promise.all(setup);

// All async ops of setup complete, run callback
await options?.onStart?.(this.botInfo);

this.pollingRunning = true;
this.pollingAbortController = new AbortController();
try {
setup.push(withRetries(async () => {
await this.api.deleteWebhook({
drop_pending_updates: options?.drop_pending_updates,
}, this.pollingAbortController?.signal);
}, this.pollingAbortController?.signal));
await Promise.all(setup);

// All async ops of setup complete, run callback
await options?.onStart?.(this.botInfo);
} catch (err) {
this.pollingRunning = false;
this.pollingAbortController = undefined;
throw err;
}

// Bot was stopped during `onStart`
if (!this.pollingRunning) return;
Expand Down

0 comments on commit 45d71b6

Please sign in to comment.