<commit_before>'use strict'
let logger = require('js-logger').get('ajax')
let R = require('ramda')
let S = require('underscore.string.fp')

let path2url = (path) => {
  return `/api/${path}`
}

let ajax = (method, path, params, payload) => {
  return new Promise((resolve, reject) => {
    let url = path2url(path)
    logger.debug(`Getting ${url}`)
    let paramStr = S.join('&', R.map(([param, value,]) => {
      return `${encodeURIComponent(param)}=${encodeURIComponent(value || '')}`
    }, R.toPairs(params || {})))
    let request = new XMLHttpRequest()
    request.onreadystatechange = () => {
      if (request.readyState === XMLHttpRequest.DONE) {
        logger.debug('Received response from server:', request)
        if (request.status === 200) {
          logger.debug(`Response was successful:`, request.responseText)
          if (request.responseText != null) {
            try {
              let result = JSON.parse(request.responseText)
              resolve(result)
            } catch (error) {
              logger.warn(`Received malformed JSON from server:`, request.responseText)<commit_msg>Handle blank response<commit_after>'use strict'
let logger = require('js-logger').get('ajax')
let R = require('ramda')
let S = require('underscore.string.fp')

let path2url = (path) => {
  return `/api/${path}`
}

let ajax = (method, path, params, payload) => {
  return new Promise((resolve, reject) => {
    let url = path2url(path)
    logger.debug(`Getting ${url}`)
    let paramStr = S.join('&', R.map(([param, value,]) => {
      return `${encodeURIComponent(param)}=${encodeURIComponent(value || '')}`
    }, R.toPairs(params || {})))
    let request = new XMLHttpRequest()
    request.onreadystatechange = () => {
      if (request.readyState === XMLHttpRequest.DONE) {
        logger.debug('Received response from server:', request)
        if (request.status === 200) {
          logger.debug(`Response was successful:`, request.responseText)
          if (!S.isBlank(request.responseText)) {
            try {
              let result = JSON.parse(request.responseText)
              resolve(result)
            } catch (error) {
              logger.warn(`Received malformed JSON from server:`, request.responseText)
{'fraction_non_alphanumeric': 0.1622103386809269, 'fraction_numerical': 0.004456327985739751, 'mean_word_length': 3.0523465703971118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1395132', 'n_tokens_mistral': 659, 'n_tokens_neox': 659, 'n_words': 150}