Docs Reference

Errors

Error classes and codes the SDK throws, and how to recover from each.

Every error the SDK throws on purpose is a HydraBridgeError with a stable code string, a human-readable message, and optional details. Branch on the class or the code, never on the message text: messages may be reworded between releases, codes will not.

Error classes

ClassCodeThrown when
HydraBridgeErroranyBase class. Also thrown directly for validation, connection and host-reported errors.
HydraTimeoutErrorERR_TIMEOUTA request or the handshake exceeded its timeout, or the host reported a timeout.
HydraUserRejectedErrorERR_USER_REJECTEDThe user rejected a wallet prompt or cancelled.
HydraTransportErrorERR_TRANSPORT_FAILED (default) or a custom codeinit() runs outside an iframe, the transport has no window to post to or was destroyed, postMessage threw (ERR_POSTMESSAGE_FAILED), or hostOrigin is missing or invalid.
HydraSecurityErrorERR_UNTRUSTED_ORIGINThe wildcard origin '*' was used outside a known development or test environment.
HydraStorageErrorERR_STORAGE_UNAVAILABLEStorage is blocked, or the host storage relay failed, timed out or was destroyed.

All classes take (message, details?), except HydraBridgeError(message, code, details?) and HydraTransportError(message, code?, details?).

Error codes

ERROR_CODES holds the stable codes, and ErrorCode is the matching type (it also accepts any other string):

CodeClassMeaning
ERR_TIMEOUTHydraTimeoutErrorSee above.
ERR_USER_REJECTEDHydraUserRejectedErrorSee above.
ERR_NOT_IN_IFRAMEHydraTransportError (also HydraBridgeError from ping())The page is not inside an iframe, so there is no host shell.
ERR_UNTRUSTED_ORIGINHydraSecurityErrorSee above.
ERR_STORAGE_UNAVAILABLEHydraStorageErrorSee above. The host can also send it when its own storage fails.
ERR_BRIDGE_NOT_CONNECTEDHydraBridgeErrorinit() has not completed, the handshake was cancelled, or the client was disconnected or destroyed.
ERR_WALLET_NOT_CONNECTEDHydraBridgeErrorSent by the host: no wallet is connected in the host.
ERR_INVALID_PARAMSHydraBridgeErrorAn argument failed validation (empty or invalid transaction CBOR, bad address, bad payload hex, bad orientation or haptic pattern).
ERR_INVALID_RESPONSEHydraBridgeErrorThe host answered with a value of the wrong shape (for example an unreadable change address). With signTx(..., { mergeWitnesses: true }), the wallet's witness set could not be merged; it is kept in details.witnessSet.

Other codes

These are in ERROR_CODES and can appear on a HydraBridgeError (or HydraTransportError), except ERR_UNSUPPORTED_METHOD, which only a host sends:

CodeMeaning
ERR_TRANSPORT_FAILEDDefault code of HydraTransportError when no more specific code applies.
ERR_INVALID_OPTIONSClient or transport options are invalid: neither transport nor hostOrigin was passed, or an origin is malformed.
ERR_TRANSPORT_UNAVAILABLEA request was made without a transport.
ERR_POSTMESSAGE_FAILEDwindow.postMessage threw, usually because a value could not be cloned. Raised as HydraTransportError.
ERR_RPC_FAILEDThe host reported a failure without its own code.
ERR_UNSUPPORTED_METHODSent by the host: it does not implement the requested method.

Codes sent by the host shell inside an RPC error are passed through unchanged, so you may see codes not listed here. Treat unknown codes as generic failures. Hosts built on @hydraone-sdk/host answer with HOST_ERROR_CODES (ERR_USER_REJECTED, ERR_WALLET_NOT_CONNECTED, ERR_INVALID_PARAMS, ERR_STORAGE_UNAVAILABLE, ERR_UNSUPPORTED_METHOD, ERR_RPC_FAILED) by throwing HostRpcError(code, message).

Handling pattern

import {
  ERROR_CODES,
  HydraBridgeError,
  HydraTimeoutError,
  HydraStorageError,
  HydraSecurityError,
  HydraTransportError,
} from '@hydraone-sdk/core';

export function describeError(err: unknown): string {
  if (err instanceof HydraTimeoutError) return 'Timed out';
  if (err instanceof HydraStorageError) return 'Storage blocked';
  if (err instanceof HydraSecurityError) return 'Untrusted origin';
  if (err instanceof HydraTransportError) return 'Transport problem';
  if (err instanceof HydraBridgeError) {
    return err.code === ERROR_CODES.ERR_USER_REJECTED ? 'Cancelled' : `Error ${err.code}`;
  }
  return 'Unknown error';
}

Check the more specific subclasses before HydraBridgeError, since they all extend it. Anything that is not a HydraBridgeError is a bug in your code or a runtime failure, so rethrow or report it.

What to do for each failure

  • ERR_USER_REJECTED: not a failure. Let the user try again; do not retry automatically.
  • ERR_TIMEOUT: the request may still have succeeded on the host. For submitTx, check the chain before submitting again. Late responses are discarded.
  • ERR_BRIDGE_NOT_CONNECTED: call await client.init() before any wallet query. After destroy() create a new client.
  • ERR_STORAGE_UNAVAILABLE: data cannot be persisted. Keep the app usable without it.
  • ERR_UNTRUSTED_ORIGIN: a configuration problem, not a runtime one. Set the exact origin in hostOrigin instead of '*'.
  • ERR_INVALID_RESPONSE after signTx with mergeWitnesses: the user already signed. Merge details.witnessSet yourself with applyWitnessSet(cbor, witnessSet), or report the host bug; do not ask the user to sign again blindly.

Serialization and safety

error.toJSON() returns { name, code, message, details, stack }. Strip stack and details before sending an error to a remote service if they might contain wallet addresses or tokens.

Error messages created by the SDK never contain secrets on their own, but details is free-form and can echo what the host sent.

Next steps