From b6afa3954e094e91d449f3e294940d1130c5622a Mon Sep 17 00:00:00 2001 From: Degiorgi Giovanni Date: Fri, 9 Sep 2016 08:18:12 +0200 Subject: [PATCH] added check of CB before calling the method apply --- lib/telegrambot.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/telegrambot.js b/lib/telegrambot.js index 8a320d4..aff9f40 100755 --- a/lib/telegrambot.js +++ b/lib/telegrambot.js @@ -46,9 +46,10 @@ TelegramBot.unwrap = function(cb) { // by passing the error object as the first parameter. if (!err && body && body.ok === false) err = TelegramBot.error(body.description, body.error_code, res.statusCode); if (!err && res.statusCode != 200) err = TelegramBot.error('HTTP status ' + res.statusCode + ' returned.', res.statusCode, res.statusCode); - if (err) return cb.apply(self, [err]); - - cb.apply(self, [null, body.result]); + if(cb!=null && cb!=undefined){ + if (err) return cb.apply(self, [err]); + cb.apply(self, [null, body.result]); + } } }