Registry / http-networking / httperr

httperr

JSON →
library1.0.0jsnpmunverified

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 httperr
INSTALL
IMPORT
SIG · HTTPERR
H
httperr
http-networkingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

httperr
const httperr = require('httperr');
import httperr from 'httperr';
The package is primarily designed for CommonJS. Direct ESM `import` statements may not work without a transpiler or ESM wrapper.
NotFound
const { NotFound } = require('httperr'); // or const httperr = require('httperr'); const err = new httperr.NotFound('Resource not found');
import { NotFound } from 'httperr';
Individual error constructors can be accessed as named properties on the `httperr` object. Direct named ESM imports are generally not supported without transpilation.
404 Error
const httperr = require('httperr'); const err = httperr[404]('The path could not be resolved');
const err = new httperr['404']();
Error constructors can be accessed via their numeric status code using bracket notation. The `new` keyword is optional when using the function-call syntax for specific errors (e.g., `httperr[404]()` or `httperr.NotFound()`).

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.

const httperr = require('httperr'); // Create a 404 Not Found error with a message const notFoundErr = httperr[404]('The requested resource was not found.'); console.log(notFoundErr); // Displays error object with details // { [NotFound: The requested resource was not found.] // title: 'Not Found', // name: 'NotFound', // code: 'NOT_FOUND', // statusCode: 404, // message: 'The requested resource was not found.' // } // Create a 405 Method Not Allowed error with extra information const methodErr = httperr.methodNotAllowed({ message: 'HTTP method not supported for this endpoint.', allowed: ['GET', 'POST'] }); console.log(methodErr); // { [MethodNotAllowed: HTTP method not supported for this endpoint.] // title: 'Method Not Allowed', // name: 'MethodNotAllowed', // code: 'METHOD_NOT_ALLOWED', // statusCode: 405, // message: 'HTTP method not supported for this endpoint.', // allowed: [ 'GET', 'POST' ] // } // Check error types const isNotFound = notFoundErr instanceof httperr.NotFound; // true const isHttpError = methodErr instanceof httperr.HttpError; // true const isGenericError = notFoundErr instanceof Error; // true console.log(`Is notFoundErr a NotFound error? ${isNotFound}`); console.log(`Is methodErr an HttpError? ${isHttpError}`); console.log(`Is notFoundErr a generic Error? ${isGenericError}`);
Debug
Known issues
breakingThe `httperr` package, due to its age (last major update around 2017), lacks official support for ES Modules (ESM).
fix
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.
affects: >=1.0.0
gotchaThe package is in maintenance mode; active development has ceased, and new features or bug fixes are unlikely to be implemented.
fix
While stable for existing applications, consider more actively maintained alternatives for new projects that require ongoing support, modern JavaScript features, or integrations.
affects: >=1.0.0
gotchaThe `new` keyword is optional when instantiating errors (e.g., `httperr.NotFound()` vs. `new httperr.NotFound()`). This can lead to inconsistent code styles.
fix
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')`).
affects: >=1.0.0
gotchaAccessing error constructors via numeric indices (e.g., `httperr[404]`) is less readable and discoverable than using named properties (e.g., `httperr.NotFound`).
fix
Prefer using the named error constructors (e.g., `httperr.BadRequest`, `httperr.Unauthorized`) when available, as they improve code readability and maintainability.
affects: >=1.0.0
gotchaThe 'stability 3 - stable' badge in the README refers to an outdated Node.js API documentation standard (circa Node.js 0.x) and does not reflect current stability or maintenance in the broader JavaScript ecosystem.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: httperr is not a constructor
Attempting to instantiate the main `httperr` object directly using `new httperr()`.
fix
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');`.
SyntaxError: Cannot use import statement outside a module
Trying to use `import` syntax (`import httperr from 'httperr';`) in a Node.js project configured for CommonJS (default).
fix
Use the CommonJS `require` syntax instead: `const httperr = require('httperr');`.
ReferenceError: httperr is not defined
Attempting to use `httperr` without first requiring it in a CommonJS environment.
fix
Ensure the module is imported at the top of your file: `const httperr = require('httperr');`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources