Skip to content

Latest commit

Β 

History

History
30 lines (22 loc) Β· 1.24 KB

File metadata and controls

30 lines (22 loc) Β· 1.24 KB

express-http-exception

npm version License: ISC

A lightweight, TypeScript-friendly HTTP exception class for Node.js and Express applications. Provides consistent error handling with automatic status categorization and operational error tracking.

Features

  • πŸš€ Simple & Lightweight - Minimal footprint with zero dependencies
  • πŸ“¦ TypeScript Support - Full type definitions included
  • πŸ” Automatic Status Categorization - Automatically sets fail for 4xx errors and error for 5xx errors
  • πŸ›‘οΈ Operational Error Flag - Distinguish between operational and programming errors
  • 🎯 Express-Ready - Designed to work seamlessly with Express error handlers
  • πŸ“ Stack Trace Support - Preserves stack traces for easier debugging

Installation

npm install express-http-exception
import { HTTPException } from 'express-http-exception';

// Throw HTTP errors
throw new HTTPException('User not found', 404);
throw new HTTPException('Bad request', 400);
throw new HTTPException('Server error', 500);