From 7e4cadb514346f1fc7262fb445363b9ab9beeec2 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Wed, 8 Feb 2017 11:44:42 +0300 Subject: [PATCH] src/polling: Fix bug #281 Bug: On certain errors, during polling, cause the following error to be thrown: TypeError: Cannot read property 'statusCode' of undefined This is caused when we try to access the 'response' property on the error object in the error handler (`catch(error)`). It goes missing when the error was fatal, for example, network error, thus no server response available. References: * Issue #281: https://github.com/yagop/node-telegram-bot-api/issues/281 * Reported-by: @dimawebmaker --- src/telegramPolling.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/telegramPolling.js b/src/telegramPolling.js index 365c168..6943ceb 100644 --- a/src/telegramPolling.js +++ b/src/telegramPolling.js @@ -146,7 +146,7 @@ class TelegramBotPolling { return this.request('getUpdates', opts) .catch(err => { - if (err.response.statusCode === ANOTHER_WEB_HOOK_USED) { + if (err.response && err.response.statusCode === ANOTHER_WEB_HOOK_USED) { return this._unsetWebHook(); } throw err;