export type ErrorType = 'unknown' | 'rejected' | 'expired' export interface WalletError { type: ErrorType message: string /** * EIP-1193 / JSON-RPC numeric error code from the underlying provider error, * when present. Numeric-only by design so no free-form data reaches structured * telemetry; lets `classifyError` place errors from their code (e.g. `-32002` → * `provider_error`) without inferring anything from the message. */ code?: number } /** * Custom error class that includes wallet error metadata * This is thrown by the connectors when operations fail */ export class WalletConnectorError extends Error { type: ErrorType /** See {@link WalletError.code}. Set only when the source error had a numeric code. */ code?: number constructor(walletError: WalletError) { super(walletError.message) this.name = 'WalletConnectorError' this.type = walletError.type // Finite-integer guard: a stray string/undefined/NaN/Infinity/float never // reaches the code slot telemetry treats as a structural signal. if ( typeof walletError.code === 'number' && Number.isInteger(walletError.code) ) { this.code = walletError.code } } } /** * Thrown at connect time when the wallet's supported networks and the configured * networks share no common chain, so there is nothing to connect on. Carries both * CAIP-2 id lists (non-PII) so telemetry can answer "wallet offered X, token * configured Y" — the difference between a metadata gap, a client-config mistake, * and a genuinely-unsupported wallet. It is the single most frequent connection * failure in production, so it gets a dedicated, self-describing error. */ export class NoCommonNetworkError extends WalletConnectorError { /** CAIP-2 ids the wallet's provider advertised. */ readonly walletNetworkIds: string[] /** CAIP-2 ids configured on this UWC instance. */ readonly configuredNetworkIds: string[] constructor(walletNetworkIds: string[], configuredNetworkIds: string[]) { super({ type: 'unknown', message: 'No common supported network found between wallet and configured networks' }) this.name = 'NoCommonNetworkError' this.walletNetworkIds = walletNetworkIds this.configuredNetworkIds = configuredNetworkIds } }