message: added qs parsing for when oauth errors occur
diff: @@ -134,7 +134,15 @@ Object.assign(Application.prototype, {
  var contentType = options.contentType || 'application/json';
  self.oa[method](url, self.options.accessToken, self.options.accessSecret, payload, contentType, function(err, data, res) {
  + try {
  data = JSON.parse(data);
  + } catch (ex) {
  + // data could not be parsed as JSON, it's likely because of an oauth error
  + data = qs.parse(data);
  + } finally {
  +
  + }
  +
  if (err && data && data['ErrorNumber'] >= 0) {
  var errObj = new Error(method.toUpperCase() + ' call failed with: ' + err.statusCode);
  errObj.data = data;
  @@ -189,8 +197,12 @@ Object.assign(Application.prototype, {
  self.checkExpiry()
  .then(function() {
  self.oa.delete(url, self.options.accessToken, self.options.accessSecret, function(err, data, res) {
  - if (data)
  + try {
  data = JSON.parse(data);
  + } catch (ex) {
  + // data could not be parsed as JSON, it's likely because of an oauth error
  + data = qs.parse(data);
  + }
  if (options.stream && !err) {
  // Already done
  @@ -216,7 +228,6 @@ Object.assign(Application.prototype, {
  return resolve();
  }
  -
  var ret = { response: data, res: res };
  resolve(ret);
  callback && callback(null, data, res);
  @@ -301,12 +312,19 @@ Object.assign(Application.prototype, {
  }
  self.oa.get(url, self.options.accessToken, self.options.accessSecret, function(err, data, res) {
  - data = JSON.parse(data)
  +
  + try {
  + data = JSON.parse(data);
  + } catch (ex) {
  + // data could not be parsed as JSON, it's likely because of an oauth error
  + data = qs.parse(data);
  + }
  if (options.stream && !err) {
  // Already done
  return resolve();
  }
  +
  if (err && data) {
  var errObj = new Error('GET call failed with: ' + err.statusCode);
  errObj.data = data;
  @@ -315,7 +333,6 @@ Object.assign(Application.prototype, {
  return;
  }
  -
  var ret = { response: data, res: res };
  if (err) {
  var errObj = new Error('GET call failed with: ' + err.statusCode + ' and exception: ' + JSON.stringify(data.ApiException, null, 2));
  @@ -342,7 +359,6 @@ Object.assign(Application.prototype, {
  callback && callback(null, data, res);
  }
  }, { stream: options.stream });
  -
  };
  });
  },
  