For the complete documentation index, see llms.txt. This page is also available as Markdown.

Errors

RFC 9457 Problem Details — TrustlessWorkApiError, TrustlessWorkNetworkError, and helpers.

HTTP failures from Core are RFC 9457 Problem Details. The fetch transport surfaces them as TrustlessWorkApiError. Non-problem HTTP failures throw TrustlessWorkNetworkError.

Core exports

import {
  toTrustlessWorkError,
  TrustlessWorkApiError,
  TrustlessWorkNetworkError,
  formatApiErrorMessage,
  parseProblemDetails,
  parseProblemDetailsFromResponse,
  isProblemDetails,
  ESCROW_ERROR_CODES,
  isEscrowErrorCode,
} from "@trustless-work/escrow-js";
Helper
Role

toTrustlessWorkError

Normalize thrown values → TrustlessWorkApiError when body is Problem Details

TrustlessWorkApiError

Typed error with code, status, detail, traceId, extensions, …

TrustlessWorkNetworkError

Non-problem HTTP failure (status + raw body)

formatApiErrorMessage

One-liner for logs ([CODE] detail (trace: …))

parseProblemDetails

Parse unknown JSON into ApiProblemDetails

parseProblemDetailsFromResponse

Extract Problem Details from status + body (fetch equivalent of Axios helper)

isProblemDetails

Type guard

ESCROW_ERROR_CODES / isEscrowErrorCode

Known escrow machine codes

Example

TrustlessWorkApiError fields

Accessor
Source

status

HTTP status

code

Machine-readable code

detail / message

Human detail

traceId

Correlation id

type / title / instance

Problem Details metadata

extensions

Optional escrow extensions

isEscrowError() / asEscrowProblem()

Narrow to known escrow codes

Operate and read methods throw the same error classes. Always catch as unknown and normalize with toTrustlessWorkError.