A lightweight, production-ready utility for creating consistent, structured HTTP errors in Node.js and Express applications.
Designed to standardize error handling across APIs with minimal setup.
- ✅ Custom
HttpErrorclass - ✅ Predefined HTTP error helpers (400–500)
- ✅ Clean, consistent JSON error responses
- ✅ Optional error codes & extra data
- ✅ Express error-handling middleware
- ✅ Environment-aware stack traces
- ✅ Zero dependencies
npm install clean-error-makerconst { notFound } = require("clean-error-maker");
throw notFound("User not found");All errors are instances of a custom HttpError class, extending JavaScript’s native Error while adding HTTP-specific metadata.
Each error contains:
status– HTTP status codemessage– human-readable descriptionsuccess– alwaysfalsetimestamp– ISO timestamp- optional
code– application-level error code - optional
data– extra contextual data
const {
badRequest,
unauthorized,
forbidden,
notFound,
conflict,
internal,
} = require("clean-error-maker");
throw badRequest("Invalid email format");
throw unauthorized("Login required");
throw notFound("Resource not found");These helpers automatically set:
- Correct HTTP status
- Standard error code
- Consistent error shape
const { HttpError } = require("clean-error-maker");
throw new HttpError(
422,
"Validation failed",
"VALIDATION_ERROR",
{ field: "email" }
);clean-error-maker provides a ready-to-use Express error-handling middleware.
const express = require("express");
const { notFound } = require("clean-error-maker");
const errorHandler = require("clean-error-maker/middleware");
const app = express();
app.get("/user/:id", (req, res) => {
throw notFound("User does not exist");
});
app.use(errorHandler);{
"success": false,
"status": 404,
"message": "User not found",
"code": "NOT_FOUND",
"timestamp": "2025-12-22T15:00:10.000Z"
}In development mode, stack traces are automatically included.
- Enforces a single error format across your API
- Reduces repetitive error-handling code
- Makes Express error handling predictable
- Clean separation between business logic and response formatting
- Easy to extend and maintain
- REST APIs
- Express.js applications
- Microservices
- Production-ready backend systems
This package follows Semantic Versioning.
- Breaking changes → MAJOR
- New features → MINOR
- Bug fixes → PATCH
MIT License