<commit_before>var util = require('util'),
  _ = require('lodash'),
  request = require('request'),
  Promise = require('promise'),

  helpers = require('./helpers'),
  info = require('./objects/info'),
  links = require('./objects/links'),
  profile = require('./objects/profile'),
  profiles = require('./objects/profiles'),
  update = require('./objects/update'),
  updates = require('./objects/updates'),
  user = require('./objects/user'),

  apiURL = 'https://api.bufferapp.com/1/%s.json',

  bufferCore = {
    post: function (endpoint, options, responseFilter) {
      return this.createRequest('post', endpoint, options, responseFilter)
    },

    get: function (endpoint, options, responseFilter) {
      return this.createRequest('get', endpoint, options, responseFilter)
    },

    createRequest: function (method, endpoint, options, responseFilter) {
      var requestOptions = this.buildRequest(method, endpoint, options),
        self = this

      return new Promise(function (resolve, reject) {
        self.runRequest(requestOptions, function (err, res, body) {

          if (body) {
            body = JSON.parse(body)
          }

          if (err) {
            return reject(err)
          } else if (res.statusCode !== 200 || (body && typeof(body.success) !== "undefined" && !body.success)) {
            if (body) {
              if (body.error) {
                err = new Error(util.format(body.error))
              } else {
                err = new Error(util.format(body.message))
              }

              err.errorCode = body.code<commit_msg>error handling code review changes<commit_after>var util = require('util'),
  _ = require('lodash'),
  request = require('request'),
  Promise = require('promise'),

  helpers = require('./helpers'),
  info = require('./objects/info'),
  links = require('./objects/links'),
  profile = require('./objects/profile'),
  profiles = require('./objects/profiles'),
  update = require('./objects/update'),
  updates = require('./objects/updates'),
  user = require('./objects/user'),

  apiURL = 'https://api.bufferapp.com/1/%s.json'

  const HTTP_OK = 200;

  function hasInvalidResponseBody(body) {
    return (body && typeof(body.success) !== "undefined" && !body.success);
  }

  bufferCore = {
    post: function (endpoint, options, responseFilter) {
      return this.createRequest('post', endpoint, options, responseFilter)
    },

    get: function (endpoint, options, responseFilter) {
      return this.createRequest('get', endpoint, options, responseFilter)
    },

    createRequest: function (method, endpoint, options, responseFilter) {
      var requestOptions = this.buildRequest(method, endpoint, options),
        self = this

      return new Promise(function (resolve, reject) {
        self.runRequest(requestOptions, function (err, res, body) {

          if (body) {
            body = JSON.parse(body)
          }

          if (err) {
            return reject(err)
          } else if (res.statusCode !== HTTP_OK || hasInvalidResponseBody(body)) {
            var errorMessage;
            if (body) {
              if (body.error) {
                errorMessage = body.error;
              } else {
                errorMessage = body.message;
              }

              err = new Error(util.format(errorMessage))

              err.errorCode = body.code
{'fraction_non_alphanumeric': 0.14425936942296252, 'fraction_numerical': 0.002379535990481856, 'mean_word_length': 2.5437302423603794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6672426', 'n_tokens_mistral': 919, 'n_tokens_neox': 891, 'n_words': 211}