Skip to content

tada5hi/ebec

Repository files navigation

ebec 💥

main codecov Known Vulnerabilities Conventional Commits

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

npm version

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')],
});

Full documentation

@ebec/http

npm version

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());
}

Full documentation

Contributing

npm ci
npm run build
npm run test
npm run lint

License

Made with 💚

Published under MIT License.

About

Extensible, type-safe error classes for TypeScript with automatic code derivation, message interpolation, error grouping, and JSON serialization.

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages