@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.
76 lines (75 loc) • 4.25 kB
JavaScript
import { SDKError, ErrorSeverity, ErrorCategory } from './base.js';
/**
* Network connection failed
*/
export class NetworkConnectionError extends SDKError {
constructor(message, endpoint, networkType, context = {}, options = {}) {
super(message, 'NETWORK_CONNECTION_ERROR', ErrorSeverity.HIGH, ErrorCategory.NETWORK, Object.assign(Object.assign({}, context), { rpcEndpoint: endpoint, network: networkType }), Object.assign(Object.assign({}, options), { retryable: true, solution: 'Check your internet connection and verify the network endpoint is accessible.' }));
this.endpoint = endpoint;
this.networkType = networkType;
}
toJSON() {
return Object.assign(Object.assign({}, super.toJSON()), { endpoint: this.endpoint, networkType: this.networkType });
}
}
/**
* Network timeout
*/
export class NetworkTimeoutError extends SDKError {
constructor(timeoutMs, endpoint, context = {}, options = {}) {
super(`Network request timed out after ${timeoutMs}ms`, 'NETWORK_TIMEOUT', ErrorSeverity.MEDIUM, ErrorCategory.TIMEOUT, Object.assign(Object.assign({}, context), { rpcEndpoint: endpoint }), Object.assign(Object.assign({}, options), { retryable: true, solution: 'The network request timed out. This may be due to slow network conditions or server issues.' }));
this.timeoutMs = timeoutMs;
this.endpoint = endpoint;
}
toJSON() {
return Object.assign(Object.assign({}, super.toJSON()), { timeoutMs: this.timeoutMs, endpoint: this.endpoint });
}
}
/**
* Network unavailable
*/
export class NetworkUnavailableError extends SDKError {
constructor(networkType, context = {}, options = {}) {
super(networkType ? `Network ${networkType} is unavailable` : 'Network is unavailable', 'NETWORK_UNAVAILABLE', ErrorSeverity.HIGH, ErrorCategory.NETWORK, Object.assign(Object.assign({}, context), { network: networkType }), Object.assign(Object.assign({}, options), { retryable: true, solution: 'The network is currently unavailable. Please try again later or switch to a different network.' }));
this.networkType = networkType;
}
toJSON() {
return Object.assign(Object.assign({}, super.toJSON()), { networkType: this.networkType });
}
}
/**
* Unsupported network
*/
export class UnsupportedNetworkError extends SDKError {
constructor(networkType, supportedNetworks, context = {}, options = {}) {
const message = supportedNetworks
? `Unsupported network: ${networkType}. Supported networks: ${supportedNetworks.join(', ')}`
: `Unsupported network: ${networkType}`;
super(message, 'UNSUPPORTED_NETWORK', ErrorSeverity.HIGH, ErrorCategory.NETWORK, Object.assign(Object.assign({}, context), { network: networkType }), Object.assign(Object.assign({}, options), { retryable: false, solution: supportedNetworks
? `Use one of the supported networks: ${supportedNetworks.join(', ')}`
: 'Switch to a supported network type.' }));
this.networkType = networkType;
this.supportedNetworks = supportedNetworks;
}
toJSON() {
return Object.assign(Object.assign({}, super.toJSON()), { networkType: this.networkType, supportedNetworks: this.supportedNetworks });
}
}
/**
* Network congestion
*/
export class NetworkCongestionError extends SDKError {
constructor(congestionLevel, estimatedDelay, context = {}, options = {}) {
const message = congestionLevel
? `Network congestion detected: ${congestionLevel}`
: 'Network congestion detected';
super(message, 'NETWORK_CONGESTION', ErrorSeverity.MEDIUM, ErrorCategory.NETWORK, context, Object.assign(Object.assign({}, options), { retryable: true, solution: estimatedDelay
? `Network is congested. Estimated delay: ${estimatedDelay}ms. The request will be retried.`
: 'Network is congested. The request will be retried with backoff.' }));
this.congestionLevel = congestionLevel;
this.estimatedDelay = estimatedDelay;
}
toJSON() {
return Object.assign(Object.assign({}, super.toJSON()), { congestionLevel: this.congestionLevel, estimatedDelay: this.estimatedDelay });
}
}