Repository: plotly/dash
File: dash/dash-renderer/src/components/error/menu/VersionInfo.react.js (JavaScript)

Code before:
        plotly_version: plotlyVersion
    } = config;
    const cachedVersionInfo = localStorage.getItem('cachedNewDashVersion');
    const cachedNewDashVersionLink = localStorage.getItem(
        'cachedNewDashVersionLink'
    );
    const lastFetched = localStorage.getItem('lastFetched');
    if (
        lastFetched &&
        Date.now() - Number(lastFetched) < DAY_IN_MS &&
        cachedVersionInfo
    ) {
        return {
            version: JSON.parse(cachedVersionInfo),
            link: cachedNewDashVersionLink
        };
    } else if (shouldRequestDashVersion(config)) {
        const queryParams = new URLSearchParams({
            dash_version: currentDashVersion,
            python_version: pythonVersion,
            ddk_version: ddkVersion,
            plotly_version: plotlyVersion
        }).toString();
        return fetch(dashVersionUrl + '?' + queryParams, {mode: 'cors'})
            .then(response => response.json())
            .catch(() => {
                return {};
            })
            .then(body => {
                if (body && body.version && body.link) {
                    localStorage.setItem(
                        'cachedNewDashVersion',
                        JSON.stringify(body.version)
                    );
                    localStorage.setItem('cachedNewDashVersionLink', body.link);
                    localStorage.setItem('lastFetched', Date.now());
                    return body;
                } else {
                    return {};
                }
            });
    }
}

function shouldRequestDashVersion(config) {
    const showNotificationsLocalStorage =
        localStorage.getItem('showNotifications');
    const showNotifications = config.disable_version_check
        ? false
        : showNotificationsLocalStorage !== 'false';
    const lastFetched = localStorage.getItem('lastFetched');

Review comment (suggestion):
I think the catch should be moved to the end of the tail. Since it's CORS, we can't get the regular error and it will throw on the `.json()` call and go into the last then and throw again. The catch should handle all the cases.

Code after:
        plotly_version: plotlyVersion
    } = config;
    const cachedVersionInfo = localStorage.getItem('cachedNewDashVersion');
    const cachedNewDashVersionLink = localStorage.getItem(
        'cachedNewDashVersionLink'
    );
    const lastFetched = localStorage.getItem('lastFetched');
    if (
        lastFetched &&
        Date.now() - Number(lastFetched) < DAY_IN_MS &&
        cachedVersionInfo
    ) {
        return {
            version: JSON.parse(cachedVersionInfo),
            link: cachedNewDashVersionLink
        };
    } else if (shouldRequestDashVersion(config)) {
        const queryParams = new URLSearchParams({
            dash_version: currentDashVersion,
            python_version: pythonVersion,
            ddk_version: ddkVersion,
            plotly_version: plotlyVersion
        }).toString();
        return fetch(dashVersionUrl + '?' + queryParams, {mode: 'cors'})
            .then(response => response.json())
            .then(body => {
                if (body && body.version && body.link) {
                    localStorage.setItem(
                        'cachedNewDashVersion',
                        JSON.stringify(body.version)
                    );
                    localStorage.setItem('cachedNewDashVersionLink', body.link);
                    localStorage.setItem('lastFetched', Date.now());
                    return body;
                } else {
                    return {};
                }
            })
            .catch(() => {
                return {};
            });
    }
}

function shouldRequestDashVersion(config) {
    const showNotificationsLocalStorage =
        localStorage.getItem('showNotifications');
    const showNotifications = config.disable_version_check
        ? false
        : showNotificationsLocalStorage !== 'false';
    const lastFetched = localStorage.getItem('lastFetched');