@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / IndexerUnavailableError

Class: IndexerUnavailableError

Defined in: packages/sdk/src/errors.ts:674

The SDK stopped an indexer read locally.

Details

A breaker-open, breaker-trial, or queue-full refusal leaves no request on the wire and returns at once instead of after a 30 s timeout. A live-reset can stop a retry backoff after an earlier attempt was sent. The breaker opens after IndexerLimits.breakerThreshold consecutive endpoint failures (timeouts or HTTP 429/502/503/504) and stays open for IndexerLimits.breakerCooldownMs.

When to use

Catch it to show "the indexer is not answering" at once rather than spinning a skeleton. retryAfterMs says how much cooling period is left, so a poller can sleep exactly that long.

Gotchas

A subclass of IndexerError, so existing instanceof IndexerError handling is unaffected. A gate refusal (breaker-open, breaker-trial, queue-full) means nothing reached the network: if a gate refuses a retry after an earlier attempt was sent, the read fails with that attempt's IndexerError instead. live-reset can end a retry's backoff, so an earlier attempt may have been sent. Never retry it in a tight loop — that is the storm the breaker exists to stop.

Branch on reason; the four cases want different things, and only breaker-open carries a meaningful retryAfterMs:

reasonMeansYour move
breaker-openConsecutive endpoint failures opened the breakerSleep retryAfterMs, then retry
breaker-trialThe cooling period ended and another read is the trialRetry shortly; the trial decides
queue-fullThis client already has maxQueued reads waiting for a slotBack off on your own schedule (nextBackoffDelayMs) or send less
live-resetstopLive() reset the live-read lifecycle while this read queued or backed offRetry on the SAME client; it stays usable

Example (Sleeping for exactly the cooling period)

ts
import { IndexerUnavailableError } from "@somnia-chain/markets-sdk";

try {
  await exchange.client.listBinaryMarkets();
} catch (e) {
  if (!(e instanceof IndexerUnavailableError)) throw e;
  // Only `breaker-open` carries a cooling period; the rest retry sooner.
  await new Promise((r) => setTimeout(r, e.retryAfterMs || 1_000));
}

Extends

Constructors

Constructor

new IndexerUnavailableError(operation, reason, detail, retryAfterMs, consecutiveFailures): IndexerUnavailableError

Defined in: packages/sdk/src/errors.ts:689

Creates a locally-refused indexer error.

Details

  • operation: GraphQL operation name that was refused.
  • reason: Which gate refused, and so what the caller should do next.
  • detail: Why the SDK refused, in prose.
  • retryAfterMs: Cooling period remaining. Meaningful only for breaker-open; 0 for every other reason, where the wait is the caller's own backoff rather than a period the SDK knows.
  • consecutiveFailures: Endpoint failures in a row recorded so far: timeouts and overload responses (HTTP 429, 502, 503, 504).

Parameters

operation

string

reason

IndexerRefusalReason

detail

string

retryAfterMs

number

consecutiveFailures

number

Returns

IndexerUnavailableError

Overrides

IndexerError.constructor

Properties

chainId?

readonly optional chainId?: number

Defined in: packages/sdk/src/errors.ts:253

The chain whose read failed. Set only on an exchange with two or more chains, in two cases. The account reads of SomniaMarkets (fetchBalance, fetchOpenOrders, fetchOrders, getOrdersPage, getOrderHistoryPage, fetchMyTrades, fetchPositions, fetchOpenStopOrders, watchUser) set it when the read spans more than one chain, or when the read has no market and no chain filter, also if it then touches only one chain. fetchDataStatus sets it on the error it throws when every chain fails. Absent on every other indexer error.

Inherited from

IndexerError.chainId


operation

readonly operation: string

Defined in: packages/sdk/src/errors.ts:265

Inherited from

IndexerError.operation


reason

readonly reason: IndexerRefusalReason

Defined in: packages/sdk/src/errors.ts:691


retryAfterMs

readonly retryAfterMs: number

Defined in: packages/sdk/src/errors.ts:693


consecutiveFailures

readonly consecutiveFailures: number

Defined in: packages/sdk/src/errors.ts:694