Errors
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
| Class | Code | Thrown when |
|---|---|---|
HydraBridgeError | any | Base class. Also thrown directly for validation, connection and host-reported errors. |
HydraTimeoutError | ERR_TIMEOUT | A request or the handshake exceeded its timeout, or the host reported a timeout. |
HydraUserRejectedError | ERR_USER_REJECTED | The user rejected a wallet prompt or cancelled. |
HydraTransportError | ERR_TRANSPORT_FAILED (default) or a custom code | init() 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. |
HydraSecurityError | ERR_UNTRUSTED_ORIGIN | The wildcard origin '*' was used outside a known development or test environment. |
HydraStorageError | ERR_STORAGE_UNAVAILABLE | Storage 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):
| Code | Class | Meaning |
|---|---|---|
ERR_TIMEOUT | HydraTimeoutError | See above. |
ERR_USER_REJECTED | HydraUserRejectedError | See above. |
ERR_NOT_IN_IFRAME | HydraTransportError (also HydraBridgeError from ping()) | The page is not inside an iframe, so there is no host shell. |
ERR_UNTRUSTED_ORIGIN | HydraSecurityError | See above. |
ERR_STORAGE_UNAVAILABLE | HydraStorageError | See above. The host can also send it when its own storage fails. |
ERR_BRIDGE_NOT_CONNECTED | HydraBridgeError | init() has not completed, the handshake was cancelled, or the client was disconnected or destroyed. |
ERR_WALLET_NOT_CONNECTED | HydraBridgeError | Sent by the host: no wallet is connected in the host. |
ERR_INVALID_PARAMS | HydraBridgeError | An argument failed validation (empty or invalid transaction CBOR, bad address, bad payload hex, bad orientation or haptic pattern). |
ERR_INVALID_RESPONSE | HydraBridgeError | The 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:
| Code | Meaning |
|---|---|
ERR_TRANSPORT_FAILED | Default code of HydraTransportError when no more specific code applies. |
ERR_INVALID_OPTIONS | Client or transport options are invalid: neither transport nor hostOrigin was passed, or an origin is malformed. |
ERR_TRANSPORT_UNAVAILABLE | A request was made without a transport. |
ERR_POSTMESSAGE_FAILED | window.postMessage threw, usually because a value could not be cloned. Raised as HydraTransportError. |
ERR_RPC_FAILED | The host reported a failure without its own code. |
ERR_UNSUPPORTED_METHOD | Sent 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. ForsubmitTx, check the chain before submitting again. Late responses are discarded.ERR_BRIDGE_NOT_CONNECTED: callawait client.init()before any wallet query. Afterdestroy()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 inhostOrigininstead of'*'.ERR_INVALID_RESPONSEaftersignTxwithmergeWitnesses: the user already signed. Mergedetails.witnessSetyourself withapplyWitnessSet(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
- Troubleshooting for symptoms, causes and fixes.
- Logging and debugging to see what the SDK reports.
