@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
88 lines (84 loc) • 3.1 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 2.0.0
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
;
const result = require('../../../result.cjs');
const ajaxError = require('../../../http/ajax-error.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class AbstractProcessing {
static {
__name(this, "AbstractProcessing");
}
// region prepareItems ////
/**
* Template method. The soft-error envelope guard lives here ONCE so v2 and v3
* can't drift on it (#228 — hoisted from the duplicated #145 fix).
*
* When the batch CALL itself soft-errors (a top-level code in the restriction
* manager's `exceptionCodeForSoft` set, surfaced as a soft `Result` instead of
* a throw), the envelope carries `{ error }` and no `result`, so
* `response.getData()` is `undefined`. Skip per-row parsing — it would
* dereference `getData()!.result` — and let {@link handleResults} surface the
* top-level errors. The version-specific success path is {@link _prepareItemsSuccess}.
*/
async prepareItems(commands, responseHelper) {
const results = /* @__PURE__ */ new Map();
if (!responseHelper.response.isSuccess) {
return results;
}
return this._prepareItemsSuccess(commands, responseHelper, results);
}
// endregion ////
// region handleResults ////
/**
* Template method. Same single soft-error guard as {@link prepareItems} (#228):
* there is no per-row data and `getData()` is `undefined`, so surface the
* envelope's top-level errors and return an empty data map instead of
* dereferencing `getData()!.time`. The version-specific success path is
* {@link _handleResultsSuccess}.
*/
async handleResults(commands, results, responseHelper) {
const result$1 = new result.Result();
if (!responseHelper.response.isSuccess) {
for (const [index, error] of responseHelper.response.errors) {
result$1.addError(error, index);
}
result$1.setData({
result: /* @__PURE__ */ new Map(),
time: void 0
});
return result$1;
}
return this._handleResultsSuccess(commands, results, responseHelper, result$1);
}
// endregion ////
// region Tools ////
_getBatchResultByIndex(data, index) {
if (!data) return void 0;
if (Array.isArray(data)) {
return data[index];
}
return data[index];
}
_createErrorFromAjaxResult(ajaxResult) {
if (ajaxResult.hasError("base-error")) {
return ajaxResult.errors.get("base-error");
}
return new ajaxError.AjaxError({
code: "JSSDK_BATCH_SUB_ERROR",
description: ajaxResult.getErrorMessages().join("; "),
status: ajaxResult.getStatus(),
requestInfo: { ...ajaxResult.getQuery() },
originalError: ajaxResult.getErrors().next().value
});
}
// endregion ////
}
exports.AbstractProcessing = AbstractProcessing;
//# sourceMappingURL=interface-strategy.cjs.map