Catch errors while parsing JSON

experimental
Yago 10 years ago
parent 5a983362d7
commit 186d1e3a5c
  1. 7
      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 {

Loading…
Cancel
Save