<commit_before>import merge from 'lodash/object/merge';
import config from '../../config';

export default function createFetchAction(options) {
  const {
    bailout,
    body,
    endpoint,
    method = 'get',
    params,
    transform,
    type,
    doDispatch = true,
  } = options;
  const { request, success = {}, failure = {} } = options;
  return (dispatch, getState) => {
    const state = getState();
    const headers = {
      'Authorization': state.auth.bearer ? `Bearer ${state.auth.bearer}` : '',
    };
    function resolve(obj) {
      return typeof obj === 'function' ? obj(state) : obj;
    }

    if (bailout && bailout(state)) return null;

    if (request && doDispatch) dispatch({ type, ...request });

    const apiRoot = config.apiRoot;
    return $.ajax({
      url: resolve(endpoint),
      method,
      headers,
      data: body,
    }).then((data, textStatus, jqXHR) => {
      if (doDispatch) {
        dispatch(merge({
          type,
          payload: transform ? transform({ data, state }) : data,
        }, resolve(success)));
      }
      return data;
    }, (jqXHR, textStatus, errorThrown) => {
      if (doDispatch) {
        dispatch(merge({
          type,
          error: jqXHR.responseJSON,
        }, resolve(failure)));
      }
      return Promise.reject(response.data);
    });
  };
}<commit_msg>send ajax resut using json.<commit_after>import merge from 'lodash/object/merge';
import config from '../../config';

export default function createFetchAction(options) {
  const {
    bailout,
    body,
    endpoint,
    method = 'get',
    params,
    transform,
    type,
    doDispatch = true,
  } = options;
  const { request, success = {}, failure = {} } = options;
  return (dispatch, getState) => {
    const state = getState();
    const headers = {
      'Authorization': state.auth.bearer ? `Bearer ${state.auth.bearer}` : '',
    };
    function resolve(obj) {
      return typeof obj === 'function' ? obj(state) : obj;
    }

    if (bailout && bailout(state)) return null;

    if (request && doDispatch) dispatch({ type, ...request });

    const apiRoot = config.apiRoot;
    return $.ajax({
      url: resolve(endpoint),
      method,
      headers,
      data: JSON.stringify(body),
      processData: false,
      contentType: 'application/json',
    }).then((data, textStatus, jqXHR) => {
      if (doDispatch) {
        dispatch(merge({
          type,
          payload: transform ? transform({ data, state }) : data,
        }, resolve(success)));
      }
      return data;
    }, (jqXHR, textStatus, errorThrown) => {
      if (doDispatch) {
        dispatch(merge({
          type,
          error: jqXHR.responseJSON,
        }, resolve(failure)));
      }
      return Promise.reject(response.data);
    });
  };
}
{'fraction_non_alphanumeric': 0.14879885263535317, 'fraction_numerical': 0.0, 'mean_word_length': 2.3453237410071943, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5914422', 'n_tokens_mistral': 832, 'n_tokens_neox': 825, 'n_words': 206}