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
Base error class with automatic code derivation, message interpolation, error catalogs, and JSON serialization. Zero runtime dependencies.
npm install @ebec/coreimport { 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')],
});43 pre-built HTTP error classes (4xx/5xx) extending @ebec/core with status codes, status messages, and duck-typed type guards.
npm install @ebec/httpimport { 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());
}npm ci
npm run build
npm run test
npm run lintMade with 💚
Published under MIT License.