From 50e3970c9396b74eaa9082b6ea3c87f535f381fa Mon Sep 17 00:00:00 2001 From: Mikhail Chechnev Date: Sun, 4 May 2025 17:58:07 +0300 Subject: [PATCH] =?UTF-8?q?WEBAPP:=20=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80?= =?UTF-8?q?=D0=B6=D0=BA=D0=B0=20AbortController=20=D0=B4=D0=BB=D1=8F=20exe?= =?UTF-8?q?cuteStored?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/context/backend.js | 6 ++++-- app/core/client.js | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/context/backend.js b/app/context/backend.js index 5e0e4f3..420c48d 100644 --- a/app/context/backend.js +++ b/app/context/backend.js @@ -64,7 +64,8 @@ export const BackEndContext = ({ client, children }) => { throwError = true, showErrorMessage = true, fullResponse = false, - spreadOutArguments = true + spreadOutArguments = true, + signal = null } = {}) => { try { if (loader !== false) showLoader(loaderMessage); @@ -76,7 +77,8 @@ export const BackEndContext = ({ client, children }) => { tagValueProcessor, attributeValueProcessor, throwError, - spreadOutArguments + spreadOutArguments, + signal }); if (fullResponse === true || isRespErr(result)) return result; else return result.XPAYLOAD; diff --git a/app/core/client.js b/app/core/client.js index 7c5ac88..a2b35cc 100644 --- a/app/core/client.js +++ b/app/core/client.js @@ -34,6 +34,7 @@ const ERR_APPSERVER = "Ошибка сервера приложений"; //Об const ERR_UNEXPECTED = "Неожиданный ответ сервера"; //Неожиданный ответ сервера const ERR_NETWORK = "Ошибка соединения с сервером"; //Ошибка сети const ERR_UNAUTH = "Сеанс завершен. Пройдите аутентификацию повторно."; //Ошибка аутентификации +const ERR_ABORTED = "Запрос прерван принудительно"; //----------- //Тело модуля @@ -76,7 +77,16 @@ const getRespErrMessage = resp => (isRespErr(resp) && resp.SMESSAGE ? resp.SMESS const getRespPayload = resp => (resp && resp.XPAYLOAD ? resp.XPAYLOAD : null); //Исполнение действия на сервере -const executeAction = async ({ serverURL, action, payload = {}, isArray, transformTagName, tagValueProcessor, attributeValueProcessor } = {}) => { +const executeAction = async ({ + serverURL, + action, + payload = {}, + isArray, + transformTagName, + tagValueProcessor, + attributeValueProcessor, + signal = null +} = {}) => { console.log(`EXECUTING ${action ? action : ""} ON ${serverURL} WITH PAYLOAD:`); console.log(payload ? payload : "NO PAYLOAD"); let response = null; @@ -92,11 +102,14 @@ const executeAction = async ({ serverURL, action, payload = {}, isArray, transfo body: await buildXML(rqBody), headers: { "content-type": "application/xml" - } + }, + ...(signal ? { signal } : {}) }); } catch (e) { + //Прервано принудительно + if (signal?.aborted === true) throw new Error(ERR_ABORTED); //Сетевая ошибка - throw new Error(`${ERR_NETWORK}: ${e.message}`); + else throw new Error(`${ERR_NETWORK}: ${e.message || "неопределённая ошибка"}`); } //Проверим на наличие ошибок HTTP - если есть вернём их if (!response.ok) throw new Error(`${ERR_APPSERVER}: ${response.statusText}`); @@ -136,7 +149,8 @@ const executeStored = async ({ tagValueProcessor, attributeValueProcessor, throwError = true, - spreadOutArguments = false + spreadOutArguments = false, + signal = null } = {}) => { let res = null; try { @@ -157,7 +171,8 @@ const executeStored = async ({ payload: { SSTORED: stored, XARGUMENTS: serverArgs, SRESP_ARG: respArg }, isArray, tagValueProcessor, - attributeValueProcessor + attributeValueProcessor, + signal }); if (spreadOutArguments === true && Array.isArray(res?.XPAYLOAD?.XOUT_ARGUMENTS)) { let spreadArgs = {};