
window.safeFetch = function(url, options = {}) {
    return fetch(url, options).then(response => {
        if (response.status === 401) {
            window.location.href = `${window.location.origin}/telezab/login`;
            throw new Error("Unauthorized");
        }
        return response;
    });
};


window.safeFetchJson = function(url, options = {}) {
    return fetch(url, options).then(response => {
        if (response.status === 401) {
            window.location.href = `${window.location.origin}/telezab/login`;
            throw new Error("Unauthorized");
        }
        return response.json();
    });
};