Skip to content

Error Handling

Reactive uses a structured error hierarchy rooted in BaseError. Every error includes a human-readable message, a short name, and optional metadata.

BaseError

All Reactive errors extend BaseError:

typescript
import { BaseError } from '@growae/reactive'

try {
  await spend(config, { recipient: 'ak_...', amount: '10' })
} catch (error) {
  if (error instanceof BaseError) {
    console.log(error.shortMessage) // human-readable summary
    console.log(error.name) // error class name
    console.log(error.details) // additional context
  }
}

Error Categories

Configuration Errors

ErrorWhen
NetworkNotConfiguredErrorTarget network is not in the config
ConnectorNotFoundErrorConnector is not registered
StorageErrorStorage read/write failed

Connection Errors

ErrorWhen
ConnectorNotConnectedErrorAction requires a connected wallet
ConnectorAlreadyConnectedErrorAttempting to connect when already connected
UserRejectedRequestErrorUser rejected the wallet prompt

Transaction Errors

ErrorWhen
InsufficientBalanceErrorNot enough AE for the transaction
TransactionRejectedErrorNode rejected the transaction
TransactionExpiredErrorTransaction TTL exceeded

Contract Errors

ErrorWhen
ContractNotFoundErrorNo contract at the specified address
ContractCallErrorContract call reverted or failed
ContractDeployErrorDeployment failed

Node Errors

ErrorWhen
NodeRequestErrorHTTP request to AE node failed
NodeTimeoutErrorNode request timed out

Catching Specific Errors

typescript
import {
  InsufficientBalanceError,
  ConnectorNotConnectedError,
} from '@growae/reactive'

try {
  await spend(config, { recipient: 'ak_...', amount: '10' })
} catch (error) {
  if (error instanceof InsufficientBalanceError) {
    console.log('Not enough AE:', error.shortMessage)
  } else if (error instanceof ConnectorNotConnectedError) {
    console.log('Please connect your wallet first')
  } else {
    throw error
  }
}

Error Types per Action

Every action exports its error union type:

typescript
import type {
  SpendErrorType,
  GetBalanceErrorType,
  CallContractErrorType,
} from '@growae/reactive'

Use these types for exhaustive error handling in TypeScript.

TanStack Query Integration

When using Reactive with framework packages (React, Vue, Solid), errors are surfaced through TanStack Query's error state:

typescript
const { error } = useBalance({ address: 'ak_...' })

if (error) {
  // error is typed as GetBalanceErrorType
  console.log(error.shortMessage)
}