601if (!window.tildaMembers.endpoint) {602window.tildaMembers.endpoint = tma__getMembersEndpoint();603}604605const endpoint = window.tildaMembers.endpoint;606const retryWithFallback = () => {607if (endpoint.indexOf('members.tilda') === -1) return false;608609window.tildaMembers.endpoint = tma__getMembersEndpoint(true);610tma__request(url, data, submit, funcSuccess, isFormData);611return true;612
}; // После сетевого сбоя изменяющий запрос мог уже выполниться на сервере. const canRetryNetworkError = /^\/api\/get[a-z]+\/$/.test(url); xhr.open('POST', endpoint + url, true); if (!isFormData) { xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); } xhr.onload = function () { if (xhr.status >= 200 && xhr.status < 400) { if (funcSuccess) funcSuccess(xhr.response); tma__enabledSubmit(submit); } else { if ( (xhr.status >= 500 || xhr.status >= 408 || xhr.status >= 410 || xhr.status >= 429 || xhr.statusText === 'timeout' || (xhr.status === 0 && xhr.readyState === 4 && xhr.statusText === '')) && retryWithFallback() ) { return; } // Добавляем функцию для отправки данных об ошибках в API JS Errors // Запросы, которые не будут отправляться в статистику, так как имею данные пользователей var notRequestURL = [ 'login', 'recoverpassword', 'registration', 'getprofile', 'editprofile', 'editpassword', ]; var isNotRequestURL = false; for (var i = 0; i < notRequestURL.length; i++) { if (url.indexOf(notRequestURL[i]) !== -1) { isNotRequestURL = true; break; } } if (!isNotRequestURL) { if (!window.tildaMembers.is_init_errors_app) { // <-- Подключение скрипта отвечающего за сбор ошибок --> tma__loadJS(tma__getStaticCdnHost() + '/js/tilda-errors-app-1.0.min.js'); // Определение сервиса window.t_apperrors__accountid = 'ma'; window.tildaMembers.is_init_errors_app = true; } tma__onFuncLoad('t_AppErrors__logApiError', function () { t_AppErrors__logApiError(url, data, xhr.statusText, xhr.status); }); } if (url.indexOf('updateonline') === -1) { tma__showRequestError(xhr.status, xhr.statusText); } tma__enabledSubmit(submit); } }; xhr.onabort = function (e) { console.info(e); tma__enabledSubmit(submit); }; xhr.onerror = function (e) { console.info(e); if (canRetryNetworkError && retryWithFallback()) return; if (!e.timeStamp || e.timeStamp > 200) { if (url.indexOf('updateonline') === -1) { tma__showNetworkError(); } } tma__enabledSubmit(submit); }; xhr.timeout = 30000; xhr.ontimeout = function () { if (canRetryNetworkError && retryWithFallback()) return; if (url.indexOf('updateonline') === -1) { tma__showNetworkError();