Cloud SDK
Error handling
Every @gray3/cloud failure is a GrayError with a stable code, HTTP status, and retryable flag.
GrayError
Every failed call throws a GrayError. It has the same fields as the API error envelope plus the HTTP status:
| Field | Required | Description |
|---|---|---|
| code | Yes | Stable machine code, such as credits_exhausted. Branch on this. |
| message | Yes | Human-readable text. Log it; do not parse it. |
| retryable | Yes | True when retrying with backoff may succeed. |
| httpStatus | Yes | HTTP status, such as 402 or 429. |
Network failures and non-JSON responses surface as provider_unavailable with retryable: true.
Handling errors
ts
import { isGrayError } from "@gray3/cloud";
try {
await gray.portfolio.getMany({ address, chainIds });
} catch (err) {
if (!isGrayError(err)) throw err;
switch (err.code) {
case "credits_exhausted": // 402
return showUpgradePrompt();
case "plan_feature_denied": // 403
case "plan_chain_denied": // 403
return showPlanLimit();
case "rate_limit_exceeded": // 429
return retryLater();
case "unsupported_capability":
return hideFeatureForChain();
default:
if (err.retryable) return retryWithBackoff();
throw err;
}
}The full list of codes is in the Error codes catalog.