<commit_before>// @flow
import {
    DATA_HAS_ERRORED,
    DATA_IS_LOADING,
    FETCH_DATA_SUCCESS
} from "./goConstants"

/**
 * All of the Redux actions related to the GO tab
 */

export function dataHasErrored(bool: boolean) {
    return {
        type: DATA_HAS_ERRORED,
        hasErrored: bool
    }
}

export function dataIsLoading(bool: boolean) {
    return {
        type: DATA_IS_LOADING,
        isLoading: bool
    }
}

export function fetchDataSuccess(data: Array<Object>) {
    return {
        type: FETCH_DATA_SUCCESS,
        data
    }
}

export function fetchData(url: string) {
    return (dispatch: Function) => {
        fetch(url)
            .then(res => {
                if (!res.ok) {
                    throw Error(res.statusText)
                }

                dispatch(dataIsLoading(false))

                return res
            })
            .then(res => res.json())
            .then(data => dispatch(fetchDataSuccess(data)))
            .catch(() => dispatch(dataHasErrored(true)))
    }
}<commit_msg>update fetch request to async/await<commit_after>// @flow
import {
    DATA_HAS_ERRORED,
    DATA_IS_LOADING,
    FETCH_DATA_SUCCESS
} from "./goConstants"

/**
 * All of the Redux actions related to the GO tab
 */

export function dataHasErrored(bool: boolean) {
    return {
        type: DATA_HAS_ERRORED,
        hasErrored: bool
    }
}

export function dataIsLoading(bool: boolean) {
    return {
        type: DATA_IS_LOADING,
        isLoading: bool
    }
}

export function fetchDataSuccess(data: Array<Object>) {
    return {
        type: FETCH_DATA_SUCCESS,
        data
    }
}

export function fetchData(url: string) {
    return async (dispatch: Function) => {
        try {
            const res = await fetch(url)
            const data = await res.json()
            if (res.ok) {
                dispatch(fetchDataSuccess(data))
            } else {
                dispatch(dataIsLoading(false))
                if (process.env.NODE_ENV !== "production") {
                    console.error(res.statusText)
                }
                throw Error(res.statusText)
            }
        } catch (error) {
            dispatch(dataHasErrored(true))
            if (process.env.NODE_ENV !== "production") {
                console.error(`Network error: ${error}`)
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.10466101694915254, 'fraction_numerical': 0.0, 'mean_word_length': 1.8241626794258374, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4997010', 'n_tokens_mistral': 705, 'n_tokens_neox': 678, 'n_words': 151}