2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-22 09:57:10 +00:00

fix: Handle rejected when open a webhook in a port that was already in use

Co-authored-by: windka <karl-heinz.wind.external@trumpf.com>
This commit is contained in:
Karl-Heinz Wind 2023-05-03 10:32:25 +02:00 committed by GitHub
parent c4164a21ce
commit ab0eb183ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,17 +45,21 @@ class TelegramBotWebHook {
/**
* Open WebHook by listening on the port
* @return {Promise}
*/
*/
open() {
if (this.isOpen()) {
return Promise.resolve();
}
return new Promise(resolve => {
return new Promise((resolve, reject) => {
this._webServer.listen(this.options.port, this.options.host, () => {
debug('WebHook listening on port %s', this.options.port);
this._open = true;
return resolve();
});
this._webServer.once('error', (err) => {
reject(err);
});
});
}