<commit_before>import { createApiError } from './ApiError';

const appendQueryParams = (url: URL, params: { [key: string]: any }) => {
    Object.keys(params).forEach((key) => {
        const value = params[key];
        if (typeof value === 'undefined') {
            return;
        }
        url.searchParams.append(key, value);
    });
};

export const createUrl = (urlString: string, params: { [key: string]: any } = {}) => {
    let url: URL;
    if (typeof window !== 'undefined') {
        url = new URL(urlString, window.location.origin);
    } else {
        url = new URL(urlString);
    }
    appendQueryParams(url, params);
    return url;
};

export const checkStatus = (response: Response, config: any) => {
    const { status } = response;

    if (status >= 200 && status < 300) {
        return response;
    }

    return response
        .json()
        .catch(() => {
            return {};
        })
        .then((data) => {
            throw createApiError('StatusCodeError', response, config, data);
        });
};

export const getDateHeader = (headers: Headers) => {
    const dateHeader = headers.get('date');
    if (!dateHeader) {
        return;
    }
    const newServerTime = new Date(dateHeader);
    if (Number.isNaN(+newServerTime)) {
        return;
    }
    return newServerTime;
};<commit_msg>Fix undefined header<commit_after>import { createApiError } from './ApiError';

const appendQueryParams = (url: URL, params: { [key: string]: any }) => {
    Object.keys(params).forEach((key) => {
        const value = params[key];
        if (typeof value === 'undefined') {
            return;
        }
        url.searchParams.append(key, value);
    });
};

export const createUrl = (urlString: string, params: { [key: string]: any } = {}) => {
    let url: URL;
    if (typeof window !== 'undefined') {
        url = new URL(urlString, window.location.origin);
    } else {
        url = new URL(urlString);
    }
    appendQueryParams(url, params);
    return url;
};

export const checkStatus = (response: Response, config: any) => {
    const { status } = response;

    if (status >= 200 && status < 300) {
        return response;
    }

    return response
        .json()
        .catch(() => {
            return {};
        })
        .then((data) => {
            throw createApiError('StatusCodeError', response, config, data);
        });
};

export const getDateHeader = (headers: Headers) => {
    const dateHeader = headers?.get?.('date');
    if (!dateHeader) {
        return;
    }
    const newServerTime = new Date(dateHeader);
    if (Number.isNaN(+newServerTime)) {
        return;
    }
    return newServerTime;
};
{'fraction_non_alphanumeric': 0.1527259148618372, 'fraction_numerical': 0.004480955937266617, 'mean_word_length': 2.332089552238806, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2960370', 'n_tokens_mistral': 792, 'n_tokens_neox': 777, 'n_words': 200}