From 186d1e3a5c63ba59879f18713bb602efc07bd435 Mon Sep 17 00:00:00 2001 From: Yago Date: Mon, 11 Jan 2016 18:28:05 +0100 Subject: [PATCH] Catch errors while parsing JSON --- src/telegram.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/telegram.js b/src/telegram.js index 4a645bb..3aea15a 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -120,7 +120,12 @@ TelegramBot.prototype._request = function (path, options) { if (resp[0].statusCode !== 200) { throw new Error(resp[0].statusCode+' '+resp[0].body); } - var data = JSON.parse(resp[0].body); + var data; + try { + data = JSON.parse(resp[0].body); + } catch (err) { + throw new Error('Error parsing Telegram response: %s', resp[0].body); + } if (data.ok) { return data.result; } else {