@roochnetwork/rooch-sdk
Version:
65 lines (64 loc) • 2.69 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var error_exports = {};
__export(error_exports, {
ErrorCategory: () => ErrorCategory,
getErrorCategoryName: () => getErrorCategoryName,
parseRoochErrorCode: () => parseRoochErrorCode,
parseRoochErrorSubStatus: () => parseRoochErrorSubStatus
});
module.exports = __toCommonJS(error_exports);
var ErrorCategory = /* @__PURE__ */ ((ErrorCategory2) => {
ErrorCategory2[ErrorCategory2["INVALID_ARGUMENT"] = 1] = "INVALID_ARGUMENT";
ErrorCategory2[ErrorCategory2["OUT_OF_RANGE"] = 2] = "OUT_OF_RANGE";
ErrorCategory2[ErrorCategory2["INVALID_STATE"] = 3] = "INVALID_STATE";
ErrorCategory2[ErrorCategory2["UNAUTHENTICATED"] = 4] = "UNAUTHENTICATED";
ErrorCategory2[ErrorCategory2["PERMISSION_DENIED"] = 5] = "PERMISSION_DENIED";
ErrorCategory2[ErrorCategory2["NOT_FOUND"] = 6] = "NOT_FOUND";
ErrorCategory2[ErrorCategory2["ABORTED"] = 7] = "ABORTED";
ErrorCategory2[ErrorCategory2["ALREADY_EXISTS"] = 8] = "ALREADY_EXISTS";
ErrorCategory2[ErrorCategory2["RESOURCE_EXHAUSTED"] = 9] = "RESOURCE_EXHAUSTED";
ErrorCategory2[ErrorCategory2["CANCELLED"] = 10] = "CANCELLED";
ErrorCategory2[ErrorCategory2["INTERNAL"] = 11] = "INTERNAL";
ErrorCategory2[ErrorCategory2["NOT_IMPLEMENTED"] = 12] = "NOT_IMPLEMENTED";
ErrorCategory2[ErrorCategory2["UNAVAILABLE"] = 13] = "UNAVAILABLE";
return ErrorCategory2;
})(ErrorCategory || {});
function parseRoochErrorCode(errorMessage) {
if (!errorMessage) {
return null;
}
const regex = /sub status (\d+)/;
const match = errorMessage.match(regex);
return match ? parseInt(match[1]) : null;
}
function parseRoochErrorSubStatus(errorMessage) {
const errorCode = parseRoochErrorCode(errorMessage);
if (!errorCode) {
return null;
}
return {
category: errorCode >> 16,
reason: errorCode & 65535
};
}
function getErrorCategoryName(code) {
return ErrorCategory[code];
}
//# sourceMappingURL=error.js.map