<commit_before>import { createAction } from 'redux-actions';
import { createThunkAction } from 'utils/redux';

import { getMeta, getGas } from 'services/emissions';

const setEmissionsData = createAction('setEmissionsData');
const setEmissionsSettings = createAction('setEmissionsSettings');
const setEmissionsLoading = createAction('setEmissionsLoading');

const getEmissions = createThunkAction(
  'getEmissions',
  params => (dispatch, state) => {
    if (!state().widgetEmissions.loading) {
      dispatch(setEmissionsLoading({ loading: true, error: false }));
      getMeta()
        .then(getMetaResponse => {
          const dataSource = getMetaResponse.data.data_source.filter(
            item => item.source === 'historical_emissions_CAIT'
          );
          const gas = getMetaResponse.data.gas.filter(
            item => item.name === 'All GHG'
          );

          if (dataSource.length && gas.length) {
            getGas({ ...params, source: dataSource[0].id, gas: gas[0].id })
              .then(getGasResponse => {
                dispatch(setEmissionsData(getGasResponse.data));
              })
              .catch(error => {
                dispatch(setEmissionsLoading({ loading: false, error: true }));
                console.error(error);
              });
          } else {
            dispatch(setEmissionsLoading({}));
          }
        })
        .catch(error => {
          dispatch(setEmissionsLoading({ loading: false, error: true }));
          console.error(error);
        });
    }
  }
);<commit_msg>fix reducer call when we don't have data<commit_after>import { createAction } from 'redux-actions';
import { createThunkAction } from 'utils/redux';

import { getMeta, getGas } from 'services/emissions';

const setEmissionsData = createAction('setEmissionsData');
const setEmissionsSettings = createAction('setEmissionsSettings');
const setEmissionsLoading = createAction('setEmissionsLoading');

const getEmissions = createThunkAction(
  'getEmissions',
  params => (dispatch, state) => {
    if (!state().widgetEmissions.loading) {
      dispatch(setEmissionsLoading({ loading: true, error: false }));
      getMeta()
        .then(getMetaResponse => {
          const dataSource = getMetaResponse.data.data_source.filter(
            item => item.source === 'historical_emissions_CAIT'
          );
          const gas = getMetaResponse.data.gas.filter(
            item => item.name === 'All GHG'
          );

          if (dataSource.length && gas.length) {
            getGas({ ...params, source: dataSource[0].id, gas: gas[0].id })
              .then(getGasResponse => {
                dispatch(setEmissionsData(getGasResponse.data));
              })
              .catch(error => {
                dispatch(setEmissionsLoading({ loading: false, error: true }));
                console.error(error);
              });
          } else {
            dispatch(setEmissionsData({}));
          }
        })
        .catch(error => {
          dispatch(setEmissionsLoading({ loading: false, error: true }));
          console.error(error);
        });
    }
  }
);
{'fraction_non_alphanumeric': 0.13173076923076923, 'fraction_numerical': 0.001282051282051282, 'mean_word_length': 2.4072052401746724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6350385', 'n_tokens_mistral': 855, 'n_tokens_neox': 839, 'n_words': 163}