@orveth/errors
v0.1.1
Published
Typed errors with stable codes and JSON normalization for Orveth.
Maintainers
Readme
@orveth/errors
Package name
@orveth/errors
Purpose
Defines a small hierarchy of application errors and a normalized JSON-friendly error shape used across packages and HTTP boundaries.
Installation
pnpm add @orveth/errorsBasic usage
import { ConfigError, HttpError, OrvethError, ValidationError } from "@orveth/errors";
throw new HttpError(404, "ORVETH_HTTP_NOT_FOUND", "Not found");
throw new ValidationError("Invalid email", { details: { field: "email" } });
throw new ConfigError("PORT is not an integer", { details: { raw: "abc" } });
throw new OrvethError("ORVETH_INVARIANT_VIOLATED", "Unexpected state");API overview
Exports:
OrvethErrorbase class (code,message, optionaldetails, optionalcause)HttpError(statusCodeplus normalized fields)ValidationError(stablecode:ORVETH_VALIDATION_FAILED)ConfigError(stablecode:ORVETH_CONFIG_INVALID)NormalizedErrorinterface andisNormalizedError()type guardOrvethError.prototype.toNormalized()
Design notes
toNormalized()is intended for logs and structured HTTP responses.HttpErroris the preferred way to represent errors that already have an HTTP status mapping.
Error behavior
HttpError and OrvethError preserve cause when provided, and toNormalized() will include a nested normalized cause only when the cause is another OrvethError.
TypeScript notes
This package ships .d.ts declarations and is authored in TypeScript strict mode.
License
Released under the MIT License. See the repository LICENSE file.
