Throws and handles HTTP errors (4xx) for Express REST APIs using service layer pattern. Version 1.2.1 is stable but has no releases since mid-2020. Provides simple factory functions (validationError, authRequired, etc.) and a middleware errorHandler. Differentiates from http-errors by being Express-specific and integrating with errorHandler middleware. Only 4 dependencies (http-status, lodash.iserror, ...). Not actively maintained but functional for many projects.
npm install express-rest-errorNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to throw validationError and attach errorHandler middleware in an Express app. Includes async route.
Use import syntax or upgrade to Node 14+ with type:'module'.
Set debug: false or conditionally enable only in development.
Consider alternatives like @curveball/http-errors or http-errors with express-http-error-handler.
Update to app.use(errorHandler({ debug: true })) instead of app.use(errorHandler).Wrap async route handlers in try/catch or use express-async-errors.
Use import { validationError } from 'express-rest-error' instead of require().Use import { errorHandler } from 'express-rest-error'.Call errorHandler({ debug: true }) to enable stack traces.