JsonRpcError

A custom error class for JSON-RPC errors returned by wallet providers. All errors thrown by request and requestRaw are instances of JsonRpcError.


Usage

import { request, JsonRpcError } from '@stacks/connect';

try {
  const result = await request('stx_transferStx', {
    recipient: 'SP2...address',
    amount: 1000000n,
  });
} catch (error) {
  if (error instanceof JsonRpcError) {
    console.error(`Error code: ${error.code}`);
    console.error(`Message: ${error.message}`);
    console.error(`Data: ${error.data}`);
  }
}

Reference Linkarrow-up-right


Definition


Properties

message

  • Type: string

A human-readable description of the error.

code

  • Type: number

A numeric error code identifying the type of error. See JsonRpcErrorCode for predefined codes.

data (optional)

  • Type: string

Optional additional data associated with the error.

cause (optional)

  • Type: Error

The original error that caused this JsonRpcError, if applicable.


Static Methods

fromResponse

Creates a JsonRpcError from a JsonRpcResponseError object returned by a wallet provider.


Instance Methods

toString

Returns a formatted string representation of the error.


Last updated

Was this helpful?