@somnia-chain/markets-sdk / native / getSomniaRpcError
Function: getSomniaRpcError()
getSomniaRpcError(
error):SomniaRpcError|null
Defined in: packages/sdk/src/native/errors.ts:144
Recover the node's own JSON-RPC error from whatever a client threw.
Use it instead of error.message whenever the message will be logged or shown:
a viem -32000 reads "Missing or invalid parameters." while the node said
"account does not exist".
Details
error: Whatever was thrown.- Returns: The node's error, or
nullif this wasn't a JSON-RPC error at all.
Example (Reading a native RPC error)
ts
import { getSomniaRpcError } from "@somnia-chain/markets-sdk/native";
try {
await native.sendSessionTransaction({ seed, gas: 21_000n, to, value });
} catch (error) {
const rpc = getSomniaRpcError(error);
console.error(rpc?.message ?? (error as Error).message); // "account does not exist"
}
Walks the cause chain and returns the innermost { code, message } pair,
which is the node's, since each wrapper layer re-describes it. Falls back to a
viem details string when the raw object is not reachable.
Parameters
error
unknown
Returns
SomniaRpcError | null