<commit_before>import Dispatcher from '../dispatcher'
import Api from '../utils/api'
import Utils from '../utils/utils'
import Constants from '../constants'
const ActionTypes = Constants.ActionTypes

const errorHandler = actionType => {
  return error => {
    Dispatcher.dispatch({
      type: actionType,
      data: response.message || response.data
    });
  };
};

export default {
  updateNumberOfLands(numberOfLandsByColour) {
    Dispatcher.dispatch({
      type: ActionTypes.NUMBER_OF_LANDS_UPDATED,
      data: numberOfLandsByColour
    });
  },

  runSimulation(numberOfLandsByColour) {
    var landsArray = Utils.createNumberOfLandsArray(numberOfLandsByColour);
    if (Utils.sum(landsArray) > 60) {
      Dispatcher.dispatch({
        type: ActionTypes.INVALID_SIMULATION,
        data: numberOfLandsByColour
      });
      return;
    }

    Dispatcher.dispatch({
      type: ActionTypes.STARTING_SIMULATION,
      data: numberOfLandsByColour
    });

    Api.createDeck(numberOfLandsByColour)
      .then(response => {
        Api.getAverages(numberOfLandsByColour)
          .then(response => {
            Dispatcher.dispatch({
              type: ActionTypes.AVERAGES_UPDATED,
              data: response.data.averages
            });
          }, errorHandler(ActionTypes.ANALYSIS_ERROR));

        Api.getMostCommonScenarios(numberOfLandsByColour)
          .then(response => {
            Dispatcher.dispatch({
              type: ActionTypes.MOST_COMMON_SCENARIOS_UPDATED,
              data: response.data.mostCommonLandScenarios
            });
          }, errorHandler(ActionTypes.ANALYSIS_ERROR));
          
      }, errorHandler(ActionTypes.SIMULATION_DIDNT_START));
  },

  updateSelectedTurn(selectedTurn) {
    Dispatcher.dispatch({
      type: ActionTypes.SELECTED_TURN_UPDATED,
      data: selectedTurn
    });
  },

  updateQueryNumbers(queryNumbers) {
    Dispatcher.dispatch({
      type: ActionTypes.QUERY_NUMBER_UPDATED,
      data: queryNumbers
    });
  }
}<commit_msg>Removed small error in api error handling<commit_after>import Dispatcher from '../dispatcher'
import Api from '../utils/api'
import Utils from '../utils/utils'
import Constants from '../constants'
const ActionTypes = Constants.ActionTypes

const errorHandler = actionType => {
  return error => {
    Dispatcher.dispatch({
      type: actionType,
      data: error.message || (error.status + ' ' + error.statusText)
    });
  };
};

export default {
  updateNumberOfLands(numberOfLandsByColour) {
    Dispatcher.dispatch({
      type: ActionTypes.NUMBER_OF_LANDS_UPDATED,
      data: numberOfLandsByColour
    });
  },

  runSimulation(numberOfLandsByColour) {
    var landsArray = Utils.createNumberOfLandsArray(numberOfLandsByColour);
    if (Utils.sum(landsArray) > 60) {
      Dispatcher.dispatch({
        type: ActionTypes.INVALID_SIMULATION,
        data: numberOfLandsByColour
      });
      return;
    }

    Dispatcher.dispatch({
      type: ActionTypes.STARTING_SIMULATION,
      data: numberOfLandsByColour
    });

    Api.createDeck(numberOfLandsByColour)
      .then(response => {
        Api.getAverages(numberOfLandsByColour)
          .then(response => {
            Dispatcher.dispatch({
              type: ActionTypes.AVERAGES_UPDATED,
              data: response.data.averages
            });
          }, errorHandler(ActionTypes.ANALYSIS_ERROR));

        Api.getMostCommonScenarios(numberOfLandsByColour)
          .then(response => {
            Dispatcher.dispatch({
              type: ActionTypes.MOST_COMMON_SCENARIOS_UPDATED,
              data: response.data.mostCommonLandScenarios
            });
          }, errorHandler(ActionTypes.ANALYSIS_ERROR));

      }, errorHandler(ActionTypes.SIMULATION_DIDNT_START));
  },

  updateSelectedTurn(selectedTurn) {
    Dispatcher.dispatch({
      type: ActionTypes.SELECTED_TURN_UPDATED,
      data: selectedTurn
    });
  },

  updateQueryNumbers(queryNumbers) {
    Dispatcher.dispatch({
      type: ActionTypes.QUERY_NUMBER_UPDATED,
      data: queryNumbers
    });
  }
}
{'fraction_non_alphanumeric': 0.1025830258302583, 'fraction_numerical': 0.0009840098400984009, 'mean_word_length': 2.7964519140989728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4215787', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1206, 'n_words': 181}