<commit_before>import config from './config';

export const getMessages = (limit=10, skip=0) => {
   return fetch(`${config.apiUrl}/messages/?limit=${limit}&skip=${skip}`, {
            credentials: 'include'
        })
        .then(res => res.json());
}

export const getStats = () => {
    return fetch(`${config.apiUrl}/messages/stats`, {
                credentials: 'include'
            })
            .then(res => res.json());
}

export const getAuthUser = () => {
    return fetch(`${config.apiUrl}/auth/info`, {
                credentials: 'include'
            })
            .then(res => res.json());
}<commit_msg>Catching network errors<commit_after>import config from './config';

const commonFetchOptions = {
    credentials: 'include'
};

const checkStatus = (res) => {
    if (res.status === 401) {
        throw new Error('Login required');
    } else if (res.status === 403) {
        throw new Error('Authorization fail');
    }

    return res;
}

const fetchWithCatch = (...args) => {
    return fetch(...args)
            .then(checkStatus)
            .then(res => res.json())
            .catch((err) => {
                console.error('Network call failed:', err)
            });
}


export const getMessages = (limit=10, skip=0) => {
   return fetchWithCatch(
       `${config.apiUrl}/messages/?limit=${limit}&skip=${skip}`,
        commonFetchOptions
    );
}

export const getStats = () => {
    return fetchWithCatch(`${config.apiUrl}/messages/stats`,
        commonFetchOptions);
}

export const getAuthUser = () => {
    return fetchWithCatch(`${config.apiUrl}/auth/info`, commonFetchOptions);
}
{'fraction_non_alphanumeric': 0.17137592137592136, 'fraction_numerical': 0.007371007371007371, 'mean_word_length': 2.480769230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5119319', 'n_tokens_mistral': 485, 'n_tokens_neox': 473, 'n_words': 97}