Custom error classes for all HTTP status codes (4xx and 5xx) in Node.js. Current stable version is 8.0.0, released periodically with low churn. Unlike generic error packages, it provides individual constructors for each status code (e.g., NotFoundError, ForbiddenError) and a factory function createHTTPError(code) that returns the correct error class by numeric status. Errors have code and status properties matching the HTTP status. This library is designed for use with Express.js error-handling middleware. It supports CommonJS only and has no runtime dependencies.
npm install http-custom-errorsVerified import paths — ran on the pinned version, not inferred.
Shows how to throw a 404 error using constructor and how to use createHTTPError factory.
Use require() instead of import.
Use err.code or err.statusCode interchangeably.
Wrap calls in try/catch or validate the code before calling.
Use const HTTPErrors = require('http-custom-errors');Run 'npm install http-custom-errors' and ensure the file is in the same project.
Use new HTTPErrors.NotFoundError(message);
No dependency data recorded yet.