You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@wthek/nestjs-middleware

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wthek/nestjs-middleware

NestJS middleware for handling and formatting errors using http-error-kit. Automatically detects and supports both Express and Fastify-based NestJS apps to ensure structured error responses with correct HTTP status codes.

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Official @wthek Extension – NestJS Middleware for http-error-kit

Seamless NestJS Error Handling with @wthek

Built for applications powered by http-error-kit, this middleware ensures that all http-error-kit errors are properly formatted and returned with the correct HTTP status codes.

💡 What the HEK?! Need a hassle-free way to manage error responses for http-error-kit errors in NestJS? @wthek/nestjs-middleware has got you covered!

Supports both Express and Fastify underlying NestJS apps out of the box.

GitHub Workflow Status npm version GitHub license GitHub Issues Codacy Badge Codacy Badge npms.io (final) npm npm bundle size (version) NPM Type Definitions Socket Badge GitHub Pages Github Sponsors Open Collective Buy Me A Coffee Patreon PayPal

Features

  • Official http-error-kit Extension – The recommended middleware for NestJS apps.
  • Dual Engine Support – Works with both Express and Fastify-based NestJS apps.
  • Auto-sets HTTP status codes – Ensures the response status matches the error type.
  • Plug-and-Play Middleware – Just drop it before starting your server!
  • Graceful Fallbacks – Passes unrecognized errors to the next middleware.

Table of Content

Installation

npm install @wthek/nestjs-middleware

Usage

Add Middleware Just Before Starting the Server

To catch all errors correctly, place KitNestJsMiddleware(app) in main.ts file before starting the NestJS server.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { KitNestJsMiddleware } from '@wthek/nestjs-middleware';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  KitNestJsMiddleware(app);
  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();

How It Works

  • Catches errors thrown in routes and middleware
  • Checks if the error is an instance of any http-error-kit Errors
  • Formats the error response and sets the correct HTTP status code
  • Passes other errors to the next middleware (so they can be handled separately)

Why Use @wthek/nestjs-middleware?

  • No more manual error handling – Status codes are automatically set.
  • Consistent API responses – Standardized errors improve debugging & logging.
  • Works perfectly with http-error-kit – Fully compatible with existing http-error-kit error structures.

Explore More WTHek Extensions

The WTHek ecosystem continues to grow with new extensions to simplify error handling across various frameworks and libraries. Stay updated with the latest tools that integrate seamlessly with http-error-kit.

Check out the official list of extensions: Official Extensions List

People

The original author of the project is Himanshu Bansal

Donations

This is all voluntary work, so if you want to support my efforts you can

You can also use the following:

BTC: qzqmpxux3m56qqhz465u8022q9z63w2sysq4u9ltwj

ETH: 0x1D59a291391a3CE17C63D5dC50F258Dc0Ab62889

License

@wthek/nestjs-middleware project is open-sourced software licensed under the MIT license by Himanshu Bansal.

Keywords

http

FAQs

Package last updated on 21 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts