@bensandee/common
Shared error classes for @bensandee packages.
Installation
pnpm add @bensandee/common
API
All classes extend Error with no additional methods or properties beyond name.
| Class | Description |
|---|---|
TransientError | External transient condition (network failure, API rate limit, etc.) |
FatalError | Fatal misconfiguration or invariant violation |
UnexpectedError | Conditions that should be unreachable |
Usage
import { TransientError, FatalError, UnexpectedError } from "@bensandee/common";
// Throw typed errors instead of plain Error
throw new TransientError("API rate limit exceeded");
throw new FatalError("Missing required DATABASE_URL");
throw new UnexpectedError("Unhandled case in switch");
// Catch and discriminate
try {
await fetchData();
} catch (error) {
if (error instanceof TransientError) {
// retry
}
}
These error classes satisfy the bensandee/no-plain-error lint rule, which forbids throw new Error(...) in favor of typed errors.