`http-errors-enhanced` is a JavaScript and TypeScript library for creating standardized HTTP error objects with additional properties. It extends the native `Error` class, providing a base `HttpError` class, specific error classes (e.g., `NotFoundError`), and a `createError` factory function. Currently stable at version 4.0.2, the library typically sees patch and minor updates for bug fixes and dependency upgrades, with major versions primarily dropping support for older Node.js runtimes. Key differentiators include its explicit support for attaching arbitrary additional properties to errors, automatic HTTP status code descriptions, `Error.cause` support since v3, and an `expose` property for controlling client visibility. It is designed to be framework-agnostic, allowing for consistent error handling across different environments. The library is ESM-only and ships with TypeScript types.
npm install http-errors-enhancedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create various HTTP errors using the `HttpError` class, specific error classes like `NotFoundError`, and the `createError` factory function, showcasing custom properties and error chaining with `Error.cause`.
Upgrade your Node.js runtime to version 22.21.0 or higher. Consider using a version manager like `nvm` (`nvm install 22 && nvm use 22`).
Upgrade your Node.js runtime to version 20 or higher. If targeting v4.x, upgrade to Node.js 22.21.0 or higher.
Always use valid HTTP status codes (400-599) or the predefined string identifiers (e.g., 'NotFound', 'BadRequest') to ensure the correct error status is set.
If you need to customize reserved properties, some might be settable directly, but generally, use different property names for custom data to avoid conflicts.
Convert your module to an ES Module (by setting `"type": "module"` in `package.json` or using `.mjs` extension) and use `import { ... } from 'http-errors-enhanced';` or use a dynamic import `import('http-errors-enhanced')`.Upgrade your Node.js runtime to version 22.21.0 or higher. Use `nvm install 22 && nvm use 22` to switch Node.js versions if you have `nvm` installed.
Ensure you are using the `new` keyword when instantiating `HttpError` (e.g., `new HttpError(...)`) or use the `createError` factory function (e.g., `createError(...)`). Verify your `import` statement is correct.
No dependency data recorded yet.