UNPKG

@kintone/rest-api-client

Version:
70 lines 3.55 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var KintoneAllRecordsError = /** @class */ (function (_super) { __extends(KintoneAllRecordsError, _super); function KintoneAllRecordsError(processedRecordsResult, unprocessedRecords, numOfAllRecords, error, chunkLength) { var _this = this; var numOfProcessedRecords = numOfAllRecords - unprocessedRecords.length; var errorIndex = KintoneAllRecordsError.extractErrorIndex(numOfProcessedRecords, error, chunkLength); var message = KintoneAllRecordsError.buildErrorMessage(numOfProcessedRecords, numOfAllRecords, errorIndex); _this = _super.call(this, message) || this; _this.name = "KintoneAllRecordsError"; _this.processedRecordsResult = processedRecordsResult; _this.unprocessedRecords = unprocessedRecords; _this.error = error; _this.errorIndex = errorIndex; _this.message = message; _this.numOfProcessedRecords = numOfProcessedRecords; _this.numOfAllRecords = numOfAllRecords; // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work // Set the prototype explicitly. Object.setPrototypeOf(_this, KintoneAllRecordsError.prototype); return _this; } KintoneAllRecordsError.parseErrorIndex = function (errors) { // TODO: use matchAll after ES2020 support var errorIndexes = []; Object.keys(errors).forEach(function (errorKey) { var result = errorKey.match(/records\[(\d+)\]/); if (result) { errorIndexes.push(Number(result[1])); } }); return errorIndexes.length > 0 ? Math.min.apply(Math, errorIndexes) : null; }; KintoneAllRecordsError.extractErrorIndex = function (numOfProcessedRecords, error, chunkLength) { if (error.bulkRequestIndex !== undefined && error.errors) { var errorParseResult = KintoneAllRecordsError.parseErrorIndex(error.errors); if (errorParseResult !== null) { return (numOfProcessedRecords + error.bulkRequestIndex * chunkLength + errorParseResult); } } return undefined; }; KintoneAllRecordsError.buildErrorMessage = function (numOfProcessedRecords, numOfAllRecords, errorIndex) { var message = ""; if (errorIndex !== undefined) { message = "An error occurred at records[".concat(errorIndex, "]. "); } message += "".concat(numOfProcessedRecords, "/").concat(numOfAllRecords, " records are processed successfully"); return message; }; return KintoneAllRecordsError; }(Error)); export { KintoneAllRecordsError }; //# sourceMappingURL=KintoneAllRecordsError.js.map