Skip to content

Client errors ​

Every error the client throws is a standard Error subclass with structured fields and a toJSON() that is safe to pipe into a structured logger.

ts
import {
  ReelVaultError,
  ReelVaultValidationError,
  NetworkError,
  TimeoutError,
  isRetryableError,
  isRetryableStatus,
} from "@reelvault/sdk/client";

ReelVaultError ​

Thrown for any non-2xx response.

MemberTypeDescription
statusnumberHTTP status code
statusTextstringHTTP status text
dataunknownParsed response body — the error envelope for ReelVault's own API
urlstringRequest URL
methodstring | undefinedRequest verb
requestIdstring | undefinedServer request id, when present
codestring | undefinedStable machine-readable code from the payload
paramsRecord<string, string | number | boolean | null> | undefinedValues for interpolating code
attemptnumber | undefinedWhich attempt failed, when retries were involved
retryableboolean (getter)true when isRetryableStatus(status)
toJSON()Record<string, unknown>Serializable snapshot

message is developer-facing (HTTP <status>: <statusText> (<METHOD> <url>)); translate code and interpolate params for anything a user sees.

NetworkError ​

The request never completed — connection refused, DNS failure, an abort caused by fetch itself.

MemberTypeDescription
urlstringRequest URL
methodstring | undefinedRequest verb
causeError | undefinedThe underlying error

TimeoutError ​

The request exceeded timeout.

MemberTypeDescription
urlstringRequest URL
timeoutnumberThe timeout that elapsed, in ms

ReelVaultValidationError ​

Raised before the request is sent, when a payload fails runtime validation against the shared TypeBox schema — the same constraints the server enforces. This gives you structured form errors without a round trip.

MemberTypeDescription
errors{ path: string; message: string; value: unknown }[]One entry per failing field
method / urlstring | undefinedRequest target

Retry helpers ​

ts
isRetryableStatus(status: number): boolean;   // 408, 425, 429, or >= 500
isRetryableError(error: unknown): boolean;    // retryable status, NetworkError, TimeoutError

The transport retries only when all of these hold:

  1. enableRetry is on and attempts remain (maxRetries, default 3);
  2. the request has not been aborted by the caller;
  3. the error is retryable; and
  4. the method is idempotent (GET, HEAD, OPTIONS, PUT, DELETE) or the request carries an idempotency-key header.

Point 4 is why a bare POST is not retried: replaying it could create the resource twice. Send an idempotency-key header when you do want a mutation retried. Retry-After on a 429/503 response is honoured; other retries use a bounded backoff with jitter.

See also ​

Released under the GNU GPL v3.