{"id":17209,"library":"easy-http-errors","title":"Easy HTTP Errors","description":"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.","status":"abandoned","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/seegno/easy-http-errors","tags":["javascript","easy","easy-http-errors","errors","http","http-errors"],"install":[{"cmd":"npm install easy-http-errors","lang":"bash","label":"npm"},{"cmd":"yarn add easy-http-errors","lang":"bash","label":"yarn"},{"cmd":"pnpm add easy-http-errors","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency providing the base HTTP error functionality.","package":"standard-http-error","optional":false}],"imports":[{"note":"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.","wrong":"const BadRequestError = require('easy-http-errors').BadRequestError;","symbol":"BadRequestError","correct":"import { BadRequestError } from 'easy-http-errors';"},{"note":"All error classes are named exports, not default exports.","wrong":"import NotFoundError from 'easy-http-errors';","symbol":"NotFoundError","correct":"import { NotFoundError } from 'easy-http-errors';"},{"note":"For CommonJS environments, destructuring is required as the package exports an object containing multiple error constructors.","wrong":"const InternalServerError = require('easy-http-errors');","symbol":"InternalServerError","correct":"const { InternalServerError } = require('easy-http-errors');"}],"quickstart":{"code":"import { BadRequestError, NotFoundError } from 'easy-http-errors';\n\nfunction handleRequest(userId, itemId) {\n  try {\n    if (!userId) {\n      throw new BadRequestError('User ID is required.');\n    }\n    // Simulate a database lookup for an item\n    const item = { id: itemId, name: 'Example Item' }; // Replace with actual lookup\n\n    if (!item || item.id !== itemId) {\n      throw new NotFoundError(`Item with ID ${itemId} not found.`);\n    }\n\n    console.log(`Processing item ${item.name} for user ${userId}`);\n    // ... further processing\n\n  } catch (error) {\n    if (error instanceof BadRequestError || error instanceof NotFoundError) {\n      console.error(`HTTP Error (${error.statusCode}): ${error.message}`);\n      // In a real application, send this error back to the client\n      // e.g., res.status(error.statusCode).json({ message: error.message, details: error.properties });\n    } else {\n      console.error('An unexpected error occurred:', error.message);\n      // Handle other types of errors, potentially a 500 Internal Server Error\n    }\n  }\n}\n\nhandleRequest('user123', 'item456');\nhandleRequest('user123', 'item999'); // Simulate not found\nhandleRequest(null, 'item456'); // Simulate bad request","lang":"javascript","description":"Demonstrates importing and throwing various HTTP error classes with custom messages, then catching and handling them based on their type."},"warnings":[{"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'.","message":"Version 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.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=2.0.0"},{"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.","message":"While 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()`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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.","cause":"This usually indicates an issue with CommonJS interoperability when using `import` statements, or incorrect named import for a CommonJS default export.","error":"TypeError: (0, _easyHttpErrors.BadRequestError) is not a constructor"},{"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');`.","cause":"Attempting to use ES module `import` syntax in a file that Node.js or your build system treats as a CommonJS module.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null}