README.md
August 18, 2026 ยท View on GitHub
ebec
A collection of extensible, type-safe error classes for TypeScript.
Every error gets a code (derived automatically from the class name if you don't set one), an optional cause for wrapping, optional errors for grouping multiple failures, and a toJSON() that serializes the full chain. No decorators, no reflection โ just plain classes you can extend, catch, and serialize.
Table of Contents
Packages
@ebec/core
Base error class with automatic code derivation, message interpolation, error catalogs, and JSON serialization. Zero runtime dependencies.
npm install @ebec/core
import { BaseError } from '@ebec/core';
// Simple string message
throw new BaseError('something failed');
// ^ code: "BASE_ERROR" (derived from class name)
// Options with message interpolation
throw new BaseError({
message: 'User {id} not found',
messageData: { id: 42 },
code: 'USER_NOT_FOUND',
});
// ^ message: "User 42 not found", code: "USER_NOT_FOUND"
// Extend for your domain โ code is derived automatically
class PaymentError extends BaseError {}
throw new PaymentError('card declined');
// ^ code: "PAYMENT_ERROR"
// Group multiple errors
throw new BaseError({
message: 'validation failed',
errors: [new Error('field required'), new Error('invalid format')],
});
@ebec/http
43 pre-built HTTP error classes (4xx/5xx) extending @ebec/core with status codes, status messages, and duck-typed type guards.
npm install @ebec/http
import { NotFoundError, isClientError } from '@ebec/http';
const error = new NotFoundError('resource not found');
// ^ status: 404, code: "NOT_FOUND", message: "resource not found"
if (isClientError(error)) {
res.status(error.status).json(error.toJSON());
}
Contributing
npm ci
npm run build
npm run test
npm run lint
License
Made with ๐
Published under MIT License.