All error classes are importable from the package:
import {
ElephantasmError,
AuthenticationError,
NotFoundError,
ValidationError,
RateLimitError,
ServerError,
} from "@elephantasm/client";Hierarchy
ElephantasmError (extends Error)
├── AuthenticationError (401)
├── NotFoundError (404)
├── ValidationError (422)
├── RateLimitError (429)
└── ServerError (5xx)
All errors extend ElephantasmError, which extends the native Error class. Each subclass sets Object.setPrototypeOf for proper instanceof support.
ElephantasmError
Base error for all SDK errors. Catch this to handle any Elephantasm error generically.
| Name | Type | Required | Description |
|---|---|---|---|
| message | string | required | Human-readable error description. |
| statusCode | number | undefined | optional | HTTP status code that triggered the error. |
| name | string | required | Always 'ElephantasmError' (or subclass name). |
import { inject, ElephantasmError } from "@elephantasm/client";
try {
const pack = await inject();
} catch (error) {
if (error instanceof ElephantasmError) {
console.error(`Error (${error.statusCode}): ${error.message}`);
}
}AuthenticationError
Thrown on 401 responses. Invalid, missing, or expired API key.
| Property | Value |
|---|---|
statusCode | 401 |
name | "AuthenticationError" |
| Default message | "Invalid or missing API key" |
When thrown:
- No API key provided and
ELEPHANTASM_API_KEYnot set - API key is invalid or revoked
- API key has expired
NotFoundError
Thrown on 404 responses. The requested resource does not exist.
| Property | Value |
|---|---|
statusCode | 404 |
name | "NotFoundError" |
| Default message | "Resource not found" |
When thrown:
animaIddoesn't exist or was deleted- Resource belongs to a different user (RLS isolation)
ValidationError
Thrown on 422 responses. Request parameters failed server-side validation.
| Property | Value |
|---|---|
statusCode | 422 |
name | "ValidationError" |
| Default message | "Validation error" |
When thrown:
- Missing required fields (
eventType,content) importanceScoreoutside 0.0–1.0 range- Invalid enum values
RateLimitError
Thrown on 429 responses. Too many requests or plan usage limit exceeded.
| Property | Value |
|---|---|
statusCode | 429 |
name | "RateLimitError" |
| Default message | "Rate limit exceeded" |
When thrown:
- Too many API requests in a short period
- Monthly event or pack limit reached for your plan
See Error Handling for retry strategies with exponential backoff.
ServerError
Thrown on 5xx responses. An unexpected error occurred on the Elephantasm backend.
| Property | Value |
|---|---|
statusCode | 500 |
name | "ServerError" |
| Default message | "Server error" |
When thrown:
- Internal server errors
- Temporary service disruptions
Error Handling Pattern
Use instanceof to catch specific errors:
import { extract } from "@elephantasm/client";
import {
AuthenticationError,
RateLimitError,
ElephantasmError,
} from "@elephantasm/client";
try {
await extract("message.in", "Hello!", { role: "user" });
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Check your API key");
} else if (error instanceof RateLimitError) {
console.error("Slow down — retry after a delay");
} else if (error instanceof ElephantasmError) {
console.error(`Unexpected error (${error.statusCode}): ${error.message}`);
}
}For practical error handling patterns including retry logic and null pack handling, see the Error Handling guide.