<commit_before>const DEFAULT_REQUEST_TIMEOUT = 5000;
// options { method, data, crsfToken, timeout }
export default function apiRequest(url, options) {
  options = options || {};
  let _method = options.method || 'GET';
  let timeout = options.timeout || DEFAULT_REQUEST_TIMEOUT;
  let requestOptions = {
    method: _method,
    credentials: 'same-origin',
    headers: { 'X-CSRF-Token': options.crsfToken }
  };
  if (options.data) requestOptions.body = options.data;
  let p = Promise.race([
    fetch(url, requestOptions),
    new Promise(function (resolve, reject) {
      setTimeout(() => reject(new Error('request timeout')), timeout);
    })
  ]).then( response => {
    // if not 200 or 400 throw unknown error
    try{
       if ([200, 400].indexOf(response.status) < 0) {
         throw new Error('There was an API error.  Please refresh and try again.  If you continue to see this message, please contact <EMAIL>.');
       } 
       else {
         return response.json();
       }
    }
    catch(e){
      console.log({'error': e});
    }
  });
  return p;
};
<commit_msg>resolve conflicts<commit_after>const DEFAULT_REQUEST_TIMEOUT = 5000;
// options { method, data, crsfToken, timeout }
export default function apiRequest(url, options) {
  options = options || {};
  let _method = options.method || 'GET';
  let timeout = options.timeout || DEFAULT_REQUEST_TIMEOUT;
  let requestOptions = {
    method: _method,
    credentials: 'same-origin',
    headers: { 'X-CSRF-Token': options.crsfToken }
  };
  if (options.data) requestOptions.body = options.data;
  let p = Promise.race([
    fetch(url, requestOptions),
    new Promise(function (resolve, reject) {
      setTimeout(() => reject(new Error('request timeout')), timeout);
    })
  ]).then( response => {
    // if not 200 or 400 throw unknown error
    try{
       if ([200, 400].indexOf(response.status) < 0) {
         throw new Error('There was an API error.  Please refresh and try again.  If you continue to see this message, please contact <EMAIL>.');
       } 
       else {
         return response.json();
       }
    }
    catch(e){
      console.log({'error': e});
    }
    catch(e){
      console.log(e)
      return {};
    }
   
  });
  return p;
};

{'fraction_non_alphanumeric': 0.1375, 'fraction_numerical': 0.015178571428571428, 'mean_word_length': 2.837328767123288, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3372054', 'n_tokens_mistral': 697, 'n_tokens_neox': 668, 'n_words': 194}