Error Handling

The SDK uses a hierarchy of typed errors to help you handle different failure scenarios.

Error Hierarchy

GrvtError (base)
├── TransportError
│   ├── HttpRequestError
│   └── WebSocketRequestError
├── ApiRequestError
├── AbstractWalletError
└── GrvtInvalidOrder

GrvtError

Base error class for all SDK errors.

import { GrvtError } from "@wezzcoetzee/grvt";

try {
  await client.fetchTicker("INVALID");
} catch (error) {
  if (error instanceof GrvtError) {
    console.error("SDK error:", error.message);
  }
}

TransportError

Thrown when communication with the GRVT API fails at the network level.

HttpRequestError

Thrown when an HTTP request fails. Extends TransportError.

Property
Type
Description

response

Response | undefined

The HTTP response object

body

string | undefined

The response body text

WebSocketRequestError

Thrown when a WebSocket operation fails. Extends TransportError.

ApiRequestError

Thrown when the GRVT API returns an error response (the request succeeded, but the API rejected it).

Property
Type
Description

code

number | undefined

GRVT error code

status

number | undefined

HTTP status code

response

unknown

Raw API response

AbstractWalletError

Thrown when wallet operations fail (signing, address derivation).

GrvtInvalidOrder

Thrown by GrvtClient when order validation fails before submission.

Common causes:

  • Symbol not in loaded markets

  • Markets not loaded (loadMarkets() not called)

  • Missing tradingAccountId

  • Missing privateKey

  • Invalid order type or side

  • Missing price for limit orders

  • Price provided for market orders

Error Handling Patterns

Comprehensive Error Handling

Retrying Failed Requests

WebSocket Error Recovery

Checking Error Responses

Use isGrvtErrorResponse to check if a response is an error:

Next Steps

Last updated