Registry / web-framework / easy-http-errors

easy-http-errors

JSON →
library2.0.0jsnpmunverified

Easy HTTP Errors (easy-http-errors) is a JavaScript library designed to provide a straightforward way to handle and throw common HTTP errors within applications. It offers a set of predefined error classes, each corresponding to a standard HTTP status code (e.g., `BadRequestError` for 400, `NotFoundError` for 404, `InternalServerError` for 500). Developers can instantiate these error classes, optionally providing a custom message and additional properties, simplifying error propagation and handling in web contexts. The current stable version is 2.0.0, released in 2017, which notably dropped support for Node.js 4. Given the lack of updates since then, the project appears to be unmaintained, suggesting a slow to non-existent release cadence. Its primary differentiator lies in providing a convenient, structured hierarchy for standard HTTP exceptions, abstracting the need for manual status code assignment and message formatting.

npm install easy-http-errors
INSTALL
IMPORT
SIG · EASY-HTTP-ERRORS
E
easy-http-errors
web-frameworkjavascriptv2.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

BadRequestError
✓ import { BadRequestError } from 'easy-http-errors';
✗ const BadRequestError = require('easy-http-errors').BadRequestError;
While ES6 imports are shown in the README, the package likely uses CommonJS exports for broad Node.js compatibility given its age. Both import styles should work in v2.0.0 with appropriate transpilation or Node.js module resolution.
NotFoundError
✓ import { NotFoundError } from 'easy-http-errors';
✗ import NotFoundError from 'easy-http-errors';
All error classes are named exports, not default exports.
InternalServerError
✓ const { InternalServerError } = require('easy-http-errors');
✗ const InternalServerError = require('easy-http-errors');
For CommonJS environments, destructuring is required as the package exports an object containing multiple error constructors.

Demonstrates importing and throwing various HTTP error classes with custom messages, then catching and handling them based on their type.

import { BadRequestError, NotFoundError } from 'easy-http-errors'; function handleRequest(userId, itemId) { try { if (!userId) { throw new BadRequestError('User ID is required.'); } // Simulate a database lookup for an item const item = { id: itemId, name: 'Example Item' }; // Replace with actual lookup if (!item || item.id !== itemId) { throw new NotFoundError(`Item with ID ${itemId} not found.`); } console.log(`Processing item ${item.name} for user ${userId}`); // ... further processing } catch (error) { if (error instanceof BadRequestError || error instanceof NotFoundError) { console.error(`HTTP Error (${error.statusCode}): ${error.message}`); // In a real application, send this error back to the client // e.g., res.status(error.statusCode).json({ message: error.message, details: error.properties }); } else { console.error('An unexpected error occurred:', error.message); // Handle other types of errors, potentially a 500 Internal Server Error } } } handleRequest('user123', 'item456'); handleRequest('user123', 'item999'); // Simulate not found handleRequest(null, 'item456'); // Simulate bad request
Debug
Known issues
breakingVersion 2.0.0 dropped support for Node.js 4. Applications targeting older Node.js versions must remain on v1.x or upgrade their Node.js environment to version 6 or higher.
fix
Ensure your Node.js runtime is version 6 or higher. Alternatively, if upgrading Node.js is not possible, explicitly pin the package version to 'easy-http-errors@^1.0.0'.
affects: >=2.0.0
gotchaThe project appears to be abandoned or in deep maintenance, with the last major release (v2.0.0) dating back to 2017. Users should not expect new features, bug fixes, or security updates. This might pose a long-term risk for applications depending on active maintenance.
fix
Evaluate the stability requirements of your project. For new projects or those requiring ongoing support, consider actively maintained alternatives. For existing projects, be aware of the lack of future updates and thoroughly test for any undiscovered issues.
affects: >=2.0.0
gotchaWhile the README shows ES6 import syntax, given the release date (2017) and common practices of the time, the package likely primarily uses CommonJS `module.exports`. If encountering issues with `import` syntax, ensure your environment is set up for ES Modules or use `require()`.
fix
If using Node.js older than v12 or without explicit ES module configuration, try using `const { ErrorName } = require('easy-http-errors');`. Ensure proper Babel configuration if transpiling ES6 modules for older Node.js versions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0, _easyHttpErrors.BadRequestError) is not a constructor
This usually indicates an issue with CommonJS interoperability when using `import` statements, or incorrect named import for a CommonJS default export.
fix
Try using the CommonJS `require` syntax: `const { BadRequestError } = require('easy-http-errors');` if your environment is CommonJS. If you are in an ES Module environment, ensure your build tool or Node.js version properly handles CommonJS named exports.
SyntaxError: Cannot use import statement outside a module
Attempting to use ES module `import` syntax in a file that Node.js or your build system treats as a CommonJS module.
fix
Rename your file to `.mjs` or add `"type": "module"` to your `package.json` if using Node.js. Alternatively, convert your imports to CommonJS `require` statements: `const { BadRequestError } = require('easy-http-errors');`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
standard-http-errorrequiredCore dependency providing the base HTTP error functionality.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
easy-http-errors — npm install easy-http-errors · libregistry