Skip to content
sistemo.io beta
GitHub Docs Quickstart

Error handling (JavaScript / TypeScript)

All SDK errors subclass SistemoError.

import {
  Sandbox,
  SistemoError,    // base class
  APIError,        // non-2xx response (has .status, .detail, .code)
  AuthError,       // 401 / 403
  NotFoundError,   // 404
  RateLimitError,  // 429
} from "@sistemo/sdk";

Hierarchy

Error
└── SistemoError
    └── APIError(status, detail, code?)
        ├── AuthError       (401, 403)
        ├── NotFoundError   (404)
        └── RateLimitError  (429)

SistemoError is also thrown for client-side issues (missing API key, connection error).

Handling specific cases

import { Sandbox, AuthError, RateLimitError, APIError } from "@sistemo/sdk";

try {
  const sb = await Sandbox.create();
  const r = await sb.run("echo hi");
  console.log(r.stdout);
  await sb.close();
} catch (e) {
  if (e instanceof AuthError) {
    console.error("Check SISTEMO_API_KEY — missing, revoked, or read-only.");
  } else if (e instanceof RateLimitError) {
    console.error("Rate limited — back off and retry.");
  } else if (e instanceof APIError) {
    console.error(`API error ${e.status}: ${e.detail} (${e.code})`);
  } else {
    throw e;
  }
}

Fields on APIError

Field Type Example
status number 403
detail string "Machine quota exceeded (limit 1)."
code string \| undefined "quota_exceeded"

See API errors for all code values.