mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-30 13:58:27 +00:00
Catch errors while parsing JSON
This commit is contained in:
@@ -120,7 +120,12 @@ TelegramBot.prototype._request = function (path, options) {
|
|||||||
if (resp[0].statusCode !== 200) {
|
if (resp[0].statusCode !== 200) {
|
||||||
throw new Error(resp[0].statusCode+' '+resp[0].body);
|
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) {
|
if (data.ok) {
|
||||||
return data.result;
|
return data.result;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user