UNPKG

@gorbchain-xyz/chaindecode

Version:

GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.

115 lines (114 loc) 3.99 kB
/** * Error severity levels for the SDK */ export var ErrorSeverity; (function (ErrorSeverity) { ErrorSeverity["LOW"] = "low"; ErrorSeverity["MEDIUM"] = "medium"; ErrorSeverity["HIGH"] = "high"; ErrorSeverity["CRITICAL"] = "critical"; })(ErrorSeverity || (ErrorSeverity = {})); /** * Error categories for classification */ export var ErrorCategory; (function (ErrorCategory) { ErrorCategory["NETWORK"] = "network"; ErrorCategory["RPC"] = "rpc"; ErrorCategory["DECODER"] = "decoder"; ErrorCategory["TRANSACTION"] = "transaction"; ErrorCategory["VALIDATION"] = "validation"; ErrorCategory["CONFIGURATION"] = "configuration"; ErrorCategory["AUTHENTICATION"] = "authentication"; ErrorCategory["RATE_LIMIT"] = "rate_limit"; ErrorCategory["TIMEOUT"] = "timeout"; ErrorCategory["UNKNOWN"] = "unknown"; })(ErrorCategory || (ErrorCategory = {})); /** * Base SDK error class with enhanced error information */ export class SDKError extends Error { constructor(message, code, severity, category, context = {}, options = {}) { var _a, _b, _c; super(message); this.name = this.constructor.name; this.code = code; this.severity = severity; this.category = category; this.context = Object.assign(Object.assign({}, context), { timestamp: (_a = context.timestamp) !== null && _a !== void 0 ? _a : new Date(), sdkVersion: (_b = context.sdkVersion) !== null && _b !== void 0 ? _b : '0.1.0' }); this.retryable = (_c = options.retryable) !== null && _c !== void 0 ? _c : false; this.solution = options.solution; this.cause = options.cause; // Ensure proper prototype chain for instanceof checks Object.setPrototypeOf(this, new.target.prototype); // Capture stack trace if available if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } } /** * Convert error to JSON for logging/reporting */ toJSON() { var _a; return { name: this.name, message: this.message, code: this.code, severity: this.severity, category: this.category, context: this.context, retryable: this.retryable, solution: this.solution, stack: this.stack, cause: (_a = this.cause) === null || _a === void 0 ? void 0 : _a.message }; } /** * Get detailed error message with context */ getDetailedMessage() { let detailed = `${this.message} (Code: ${this.code})`; if (this.context.rpcEndpoint) { detailed += `\nRPC Endpoint: ${this.context.rpcEndpoint}`; } if (this.context.transactionSignature) { detailed += `\nTransaction: ${this.context.transactionSignature}`; } if (this.context.programId) { detailed += `\nProgram ID: ${this.context.programId}`; } if (this.solution) { detailed += `\nSolution: ${this.solution}`; } return detailed; } /** * Check if error is retryable */ isRetryable() { return this.retryable; } /** * Check if error is critical */ isCritical() { return this.severity === ErrorSeverity.CRITICAL; } } /** * Generic SDK error for unknown/unclassified errors */ export class GorbchainSDKError extends SDKError { constructor(message, context = {}, options = {}) { super(message, 'GORBCHAIN_SDK_ERROR', ErrorSeverity.MEDIUM, ErrorCategory.UNKNOWN, context, options); } } /** * Configuration error for invalid SDK setup */ export class ConfigurationError extends SDKError { constructor(message, context = {}, options = {}) { super(message, 'CONFIGURATION_ERROR', ErrorSeverity.HIGH, ErrorCategory.CONFIGURATION, context, Object.assign(Object.assign({}, options), { retryable: false })); } }