The `httperr` package provides a comprehensive set of JavaScript Error types, each corresponding to a standard HTTP status code. It is designed to address common issues found in similar libraries, such as incorrect stack trace capture and limited support for status codes. `httperr` version 1.0.0 is stable but appears to be in maintenance mode, with infrequent updates. A key differentiator is its ability to associate arbitrary additional data with an error object during instantiation, allowing for context-rich error handling without losing the semantic meaning of HTTP status codes. This enables developers to separate error handling logic from the final error response generation, enhancing flexibility and clarity, especially when dealing with specific HTTP headers like `Allow` or `Retry-After` for certain error types.
npm install httperrVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating HTTP errors using both numeric and named constructors, attaching custom messages and additional properties, and verifying error types using `instanceof` checks.
For Node.js projects, use `const httperr = require('httperr');`. In an ESM context, consider using an intermediary CJS-to-ESM wrapper or transpilation if absolutely necessary, but migrating to a more modern error handling library is recommended for new projects.While stable for existing applications, consider more actively maintained alternatives for new projects that require ongoing support, modern JavaScript features, or integrations.
To maintain code clarity and consistency, it is generally recommended to always use the `new` keyword when instantiating error objects (e.g., `new httperr.NotFound('Message')`).Prefer using the named error constructors (e.g., `httperr.BadRequest`, `httperr.Unauthorized`) when available, as they improve code readability and maintainability.
Developers should consult the package's GitHub repository for recent commit activity and issue tracker status to gauge its true level of current maintenance and stability.
The main `httperr` export is an object containing error constructors, not a constructor itself. You must instantiate specific errors like `new httperr.NotFound()` or `httperr.badRequest('Invalid input');`.Use the CommonJS `require` syntax instead: `const httperr = require('httperr');`.Ensure the module is imported at the top of your file: `const httperr = require('httperr');`.No dependency data recorded yet.