<commit_before>var https = require('https')
var querystring = require('querystring')
var concat = require('concat-stream')
var isArray = require('is-array')
var isEmail = require('is-email')

var BASE_URL = 'https://gender-api.com/get?'

module.exports = function (name, opts, cb) {
  if (typeof opts === 'function') {
    cb = opts
    opts = {}
  }

  var multipleNames = false
  if (isArray(name)) {
    multipleNames = true
    name = name.join(';')
  }
  var queryObject = {}
  isEmail(name) ? queryObject.email = name : queryObject.name = name

  https.get(BASE_URL + querystring.stringify(queryObject), function (res) {
    if (res.statusCode !== 200) return cb(new Error('API call failed'))

    res.pipe(concat(function (body) {
      try {
        var response = JSON.parse(body)

        if (multipleNames === true) {
          var parsedResult = {}
          response.result.map(function (result) {
            parsedResult[result.name] = result.gender
          })

          return cb(null, parsedResult, response)
        }

        cb(null, response.gender, response)
      } catch (e) {
        return cb(new Error('API returned invalid data'))
      }
    }))
  })
}<commit_msg>Return API error<commit_after>var https = require('https')
var querystring = require('querystring')
var concat = require('concat-stream')
var isArray = require('is-array')
var isEmail = require('is-email')

var BASE_URL = 'https://gender-api.com/get?'

module.exports = function (name, opts, cb) {
  if (typeof opts === 'function') {
    cb = opts
    opts = {}
  }

  var multipleNames = false
  if (isArray(name)) {
    multipleNames = true
    name = name.join(';')
  }
  var queryObject = {}
  isEmail(name) ? queryObject.email = name : queryObject.name = name

  https.get(BASE_URL + querystring.stringify(queryObject), function (res) {
    if (res.statusCode !== 200) return cb(new Error('API call failed'))

    res.pipe(concat(function (body) {
      try {
        var response = JSON.parse(body)

        if (response.errno) return cb(new Error(response.errmsg))

        if (multipleNames === true) {
          var parsedResult = {}
          response.result.map(function (result) {
            parsedResult[result.name] = result.gender
          })

          return cb(null, parsedResult, response)
        }

        cb(null, response.gender, response)
      } catch (e) {
        return cb(new Error('API returned invalid data'))
      }
    }))
  })
}
{'fraction_non_alphanumeric': 0.14053614947197401, 'fraction_numerical': 0.002437043054427295, 'mean_word_length': 2.76030534351145, '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': '3237201', 'n_tokens_mistral': 761, 'n_tokens_neox': 736, 'n_words': 183}