Core
GrayError and error handling
Stable GrayError codes for client and keystore—handle by code, not message.
Overview
All wallet SDK failures use GrayError with a stable code. Branch on code, not message text. HTTP APIs serialize the same shape.
Signature
js
import { GrayError, isGrayError } from "@gray3/core";
throw new GrayError({
code: "invalid_argument",
message: "chainId is required",
});Parameters
| Field | Required | Description |
|---|---|---|
| code | Yes | `string` — e.g. `invalid_argument`, `unauthorized`, `not_found`, `conflict`, `unsupported_capability`, `internal` |
| message | Yes | `string` — human-readable detail (may include wallet label/id) |
| retryable | No | `boolean` — optional; usually false for client/keystore errors |
Response / shape
ts
class GrayError extends Error {
code: string;
message: string;
retryable?: boolean;
}
isGrayError(err): err is GrayErrorCommon client / keystore codes
| Field | Required | Description |
|---|---|---|
| invalid_argument | No | Bad params, paths, mnemonics, addresses |
| unauthorized | No | Wrong/missing keystore PIN; locked storage |
| not_found | No | Unknown wallet / account id |
| conflict | No | Duplicate mnemonic / key / address under policy |
| unsupported_capability | No | Watch Monero; signPrepared UTXO/Monero; feature off allowlist |
| internal | No | Corrupt keystore master key / unexpected failure |
Usage
js
try {
await client.wallets.importMnemonic({ mnemonic, password: pin });
} catch (err) {
if (isGrayError(err)) {
if (err.code === "conflict") {
// show existing wallet from message / prior findMnemonic()
} else if (err.code === "unauthorized") {
// re-prompt PIN
} else if (err.code === "unsupported_capability") {
// hide or rewrite the flow (e.g. Monero watch)
}
}
throw err;
}Throws
Constructing GrayError does not throw. Prefer isGrayError at boundaries so other exceptions still surface.