{"library":"node-http-error","title":"Node.js HTTP Error Handling","description":"node-http-error provides a simple mechanism for creating and throwing HTTP-specific errors within Node.js applications, particularly useful for API development with frameworks like Express. This package allows developers to instantiate errors with a given HTTP status code, an optional custom message, and additional properties, while also automatically generating default messages for standard status codes. Key features of version 2.0.0, released in 2014, include full stack traces, the ability to omit the `new` operator when creating instances, and direct access to `status` and `statusCode` properties for integration with error handling middleware. However, this specific package by carsondarling is considered abandoned, with its last update occurring nine years ago. Developers are strongly encouraged to use more actively maintained alternatives like `http-errors` (from `jshttp`) for modern Node.js projects.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install node-http-error"],"cli":null},"imports":["const HTTPError = require('node-http-error');","next(HTTPError(500, 'Error by design.'));"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const HTTPError = require('node-http-error');\nconst express = require('express');\nconst app = express();\n\napp.get('/error', function(req, res, next) {\n  // Example of throwing a 500 Internal Server Error with a custom message\n  return next(new HTTPError(500, 'Error by design.'));\n});\n\napp.get('/not-found', function(req, res, next) {\n  // Example of throwing a 404 Not Found error using only the status code\n  return next(HTTPError(404)); \n});\n\n// Error handler middleware\napp.use(function(err, req, res, next) {\n  if (err instanceof HTTPError) {\n    res.status(err.status || err.statusCode || 500);\n    res.send(err.message || 'An unexpected error occurred.');\n  } else {\n    res.status(500).send('Unhandled server error.');\n  }\n});\n\napp.listen(3000, () => {\n  console.log('Server listening on http://localhost:3000');\n  console.log('Try visiting http://localhost:3000/error');\n  console.log('Try visiting http://localhost:3000/not-found');\n});","lang":"javascript","description":"This quickstart demonstrates how to create and throw `HTTPError` instances within an Express.js application, and how to set up a basic error handling middleware to catch and respond to these errors using their status code and message.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}