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.

119 lines (118 loc) 6.02 kB
import { SDKError, ErrorSeverity, ErrorCategory } from './base.js'; /** * Invalid address format */ export class InvalidAddressError extends SDKError { constructor(address, expectedFormat, context = {}, options = {}) { const message = expectedFormat ? `Invalid address format: ${address}. Expected: ${expectedFormat}` : `Invalid address format: ${address}`; super(message, 'INVALID_ADDRESS', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: expectedFormat ? `Ensure the address is in the correct format: ${expectedFormat}` : 'Ensure the address is a valid base58-encoded public key.' })); this.address = address; this.expectedFormat = expectedFormat; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { address: this.address, expectedFormat: this.expectedFormat }); } } /** * Invalid parameter value */ export class InvalidParameterError extends SDKError { constructor(parameterName, parameterValue, expectedType, context = {}, options = {}) { const message = expectedType ? `Invalid parameter '${parameterName}': ${parameterValue}. Expected: ${expectedType}` : `Invalid parameter '${parameterName}': ${parameterValue}`; super(message, 'INVALID_PARAMETER', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: expectedType ? `Ensure the parameter '${parameterName}' is of type: ${expectedType}` : `Check the parameter '${parameterName}' value and format.` })); this.parameterName = parameterName; this.parameterValue = parameterValue; this.expectedType = expectedType; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { parameterName: this.parameterName, parameterValue: this.parameterValue, expectedType: this.expectedType }); } } /** * Missing required parameter */ export class MissingParameterError extends SDKError { constructor(parameterName, context = {}, options = {}) { super(`Missing required parameter: ${parameterName}`, 'MISSING_PARAMETER', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: `Provide the required parameter: ${parameterName}` })); this.parameterName = parameterName; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { parameterName: this.parameterName }); } } /** * Invalid configuration */ export class InvalidConfigurationError extends SDKError { constructor(message, configField, configValue, context = {}, options = {}) { super(message, 'INVALID_CONFIGURATION', ErrorSeverity.HIGH, ErrorCategory.CONFIGURATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: 'Check the SDK configuration and ensure all required fields are properly set.' })); this.configField = configField; this.configValue = configValue; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { configField: this.configField, configValue: this.configValue }); } } /** * Invalid token amount */ export class InvalidTokenAmountError extends SDKError { constructor(amount, mintAddress, context = {}, options = {}) { super(`Invalid token amount: ${amount}`, 'INVALID_TOKEN_AMOUNT', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: 'Ensure the token amount is a positive number and within the valid range.' })); this.amount = amount; this.mintAddress = mintAddress; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { amount: this.amount, mintAddress: this.mintAddress }); } } /** * Invalid public key */ export class InvalidPublicKeyError extends SDKError { constructor(publicKey, context = {}, options = {}) { super(`Invalid public key: ${publicKey}`, 'INVALID_PUBLIC_KEY', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: 'Ensure the public key is a valid base58-encoded 32-byte public key.' })); this.publicKey = publicKey; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { publicKey: this.publicKey }); } } /** * Invalid program ID */ export class InvalidProgramIdError extends SDKError { constructor(programId, context = {}, options = {}) { super(`Invalid program ID: ${programId}`, 'INVALID_PROGRAM_ID', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: 'Ensure the program ID is a valid base58-encoded public key.' })); this.programId = programId; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { programId: this.programId }); } } /** * Invalid data format */ export class InvalidDataFormatError extends SDKError { constructor(data, expectedFormat, context = {}, options = {}) { const message = expectedFormat ? `Invalid data format. Expected: ${expectedFormat}` : 'Invalid data format'; super(message, 'INVALID_DATA_FORMAT', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: expectedFormat ? `Ensure the data is in the expected format: ${expectedFormat}` : 'Check the data format and ensure it matches the expected structure.' })); this.data = data; this.expectedFormat = expectedFormat; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { data: this.data, expectedFormat: this.expectedFormat }); } }