<commit_before>require('es6-promise').polyfill()
require('fetch-everywhere')

const GET = 'GET'
const POST = 'POST'
const POST_FILE = 'POSTFILE'
const PUT = 'PUT'
const DELETE = 'DELETE'

function JSONParseError(status, body) {
  this.name = 'JSONParseError'
  this.status = status
  this.body = body
  this.message = 'Received unexpected response from the server.'
  this.stack = (new Error()).stack
}
JSONParseError.prototype = Object.create(Error.prototype)
JSONParseError.prototype.constructor = JSONParseError

function Non200Error(status, body) {
  this.name = 'Non200Error'
  this.status = status
  this.body = body
  this.message = 'A network error occurred. Please try again.'
  this.stack = (new Error()).stack
}
Non200Error.prototype = Object.create(Error.prototype)
Non200Error.prototype.constructor = Non200Error

const contentType = {
  GET: 'application/x-www-form-urlencoded',
  POST: 'application/json',
  PUT: 'application/json',
  DELETE: 'application/json',
}

const requestFactory = (meth, notify = null) => {
  let _headers = {}

  // We need this to be able to send formData
  if (meth === POST_FILE) {
    meth = POST
  } else {
    _headers['Content-Type'] = contentType[meth]
  }

  return (token, path, body = undefined, options = {}, headers = {}) => {
    if (token) {
      _headers['Authorization'] = 'Bearer ' + token
    }

    return fetch(path, {
      ...options,
      headers: {
        ..._headers,
        ...headers
      },
      method: meth,
      body: body
    }).then(resp => {
      return resp.json().catch(() => {
        if (notify)
          notify('Received unexpected response from the server.')
        throw new JSONParseError(resp.status)
      }).then(json => {
        if (resp.status < 200 || resp.status > 300) {
          if (notify)
            notify('Received unexpected response from the server.')
          throw new Non200Error(resp.status, json)<commit_msg>Fix method headers scoping issue<commit_after>require('es6-promise').polyfill()
require('fetch-everywhere')

const GET = 'GET'
const POST = 'POST'
const POST_FILE = 'POSTFILE'
const PUT = 'PUT'
const DELETE = 'DELETE'

function JSONParseError(status, body) {
  this.name = 'JSONParseError'
  this.status = status
  this.body = body
  this.message = 'Received unexpected response from the server.'
  this.stack = (new Error()).stack
}
JSONParseError.prototype = Object.create(Error.prototype)
JSONParseError.prototype.constructor = JSONParseError

function Non200Error(status, body) {
  this.name = 'Non200Error'
  this.status = status
  this.body = body
  this.message = 'A network error occurred. Please try again.'
  this.stack = (new Error()).stack
}
Non200Error.prototype = Object.create(Error.prototype)
Non200Error.prototype.constructor = Non200Error

const contentType = {
  GET: 'application/x-www-form-urlencoded',
  POST: 'application/json',
  PUT: 'application/json',
  DELETE: 'application/json',
}

const requestFactory = (meth, notify = null) => {
  let methodHeaders = {}

  // We need this to be able to send formData
  if (meth === POST_FILE) {
    meth = POST
  } else {
    methodHeaders['Content-Type'] = contentType[meth]
  }

  return (token, path, body = undefined, options = {}, headers = {}) => {
    let finalHeaders = {
      ...methodHeaders,
      ...headers
    }

    if (token) {
      finalHeaders['Authorization'] = 'Bearer ' + token
    }

    return fetch(path, {
      ...options,
      headers: finalHeaders,
      method: meth,
      body: body
    }).then(resp => {
      return resp.json().catch(() => {
        if (notify)
          notify('Received unexpected response from the server.')
        throw new JSONParseError(resp.status)
      }).then(json => {
        if (resp.status < 200 || resp.status > 300) {
          if (notify)
            notify('Received unexpected response from the server.')
          throw new Non200Error(resp.status, json)
{'fraction_non_alphanumeric': 0.13287426676868147, 'fraction_numerical': 0.012751849018107626, 'mean_word_length': 3.093945720250522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1143280', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1157, 'n_words': 310}