message: reduce the scope upon which the try/catch is applied during API calls to Botkit Studio
diff: @@ -506,19 +506,25 @@ module.exports = function(controller) {
  console.log('Error in Botkit Studio Stats:', err);
  return reject(err);
  }
  +
  + var json = null;
  try {
  json = JSON.parse(body);
  - if (json.error) {
  - console.log('Error in Botkit Studio Stats:', json.error);
  - reject(json.error);
  - } else {
  - // console.log('** Stat recorded: ', options.form.type);
  - resolve(json);
  - }
  } catch (e) {
  console.log('Error in Botkit Studio Stats:', e);
  return reject('Invalid JSON');
  }
  +
  + if (!json || json == null) {
  + console.log('Error in Botkit Studio Stats: Response from Botkit Studio API was empty or invalid JSON');
  + return reject('Response from Botkit Studio API was empty or invalid JSON');
  + } else if (json.error) {
  + console.log('Error in Botkit Studio Stats:', json.error);
  + return reject(json.error);
  + } else {
  + resolve(json);
  + }
  +
  });
  });
  }
  