<commit_before>request = require "request"

Login = require "./Login"

run = (params) ->
  new Promise (resolve, reject) ->
    request(params, (err, res, data) ->
      if err?
        reject err
      else if res.statusCode == 200 or res.statusCode == 201
        resolve data
      else
        reject new Error "Failed with unknown error"
    )

runAuthenticated = (method, url) ->
  run(
    auth:
      user: Login.currentAccessToken()
      password: "X"
    method: method
    url: url
  )

module.exports = http = {
  request: run
  requestAuthenticated: runAuthenticated
}<commit_msg>chore (Module) Print better debug on unknown error<commit_after>request = require "request"

Login = require "./Login"

run = (params) ->
  new Promise (resolve, reject) ->
    request(params, (err, res, data) ->
      if err?
        reject err
      else if res.statusCode == 200 or res.statusCode == 201
        resolve data
      else
        reject new Error "Failed with unknown error, HTTP status '#{res.statusCode}', url '#{res.request.uri.href}'"
    )

runAuthenticated = (method, url) ->
  run(
    auth:
      user: Login.currentAccessToken()
      password: "X"
    method: method
    url: url
  )

module.exports = http = {
  request: run
  requestAuthenticated: runAuthenticated
}
{'fraction_non_alphanumeric': 0.11326609775019394, 'fraction_numerical': 0.009309542280837859, 'mean_word_length': 2.6338028169014085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '7126938', 'n_tokens_mistral': 402, 'n_tokens_neox': 389, 'n_words': 124}