forked from CITKParus/P8-Panels
WEBAPP: Поддержка AbortController для executeStored
This commit is contained in:
parent
f418951695
commit
50e3970c93
@ -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;
|
||||
|
@ -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 = {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user