1701const tsDelta = Date.now() - startTime;1702if (!xhr || (xhr.status === 0 && tsDelta < 100)) {1703reject('connection_error');1704}17051706if (xhr.status === 200) {1707try {1708const data = JSON.parse(xhr.responseText);1709if (handleRootzoneRedirect(data, rootZone)) {1710resolve(tmst__fetchData(endpoint, params));1711} else {1712
resolve(data); } } catch (error) { reject(xhr.responseText); } } else { reject('server_error'); } } }; xhr.ontimeout = () => { reject('timeout_error'); }; xhr.onerror = () => { // Проверяем время выполнения запроса при ошибке const tsDelta = Date.now() - startTime; if (!xhr || (xhr.status === 0 && tsDelta < 100)) { reject('connection_error'); } reject('network_error'); }; xhr.onabort = () => { reject('aborted_error'); }; xhr.open(method, url, true); xhr.timeout = 30000; const formData = new FormData(); for (const key in body) { formData.append(key, body[key]); } xhr.send(formData); }); function handleRootzoneRedirect(json, previousRootZone) { const rootZone = json.redirectto; if (rootZone && previousRootZone !== rootZone) { tmst__setRootZone(rootZone); return true; } return false; }}/** * Возвращает домен сервера заказов * * @returns {string} Сервер заказов */function tmst__getServerName() { const rootZone = tmst__getRootZone(); return `store.tildaapi.${rootZone}`;}/** * Возвращает корневую зону * * @returns {string} Корневая зона */function tmst__getRootZone() { if (window.tmst_rootzone) return window.tmst_rootzone; let rootZone; const allRecords = document.getElementById('allrecords'); if (allRecords) { rootZone = allRecords.getAttribute('data-tilda-root-zone'); } return rootZone || 'com';}function tmst__setRootZone(rootZone) { window.tmst_rootzone = rootZone;}/** * Получает токен * * @returns {string} Токен