npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

abs-nestjs-http-exception-filter-middleware

v0.0.4

Published

`HttpExceptionFilterMiddleware` is a custom http exception filter middleware that displays the error response with the following json format

Readme

HttpExceptionFilterMiddleware Documentation

HttpExceptionFilterMiddleware is a custom http exception filter middleware that displays the error response with the following json format

{
  "message": "A short description of the error",
  "statusCode": 400,
  "timestamp": "2024-11-19T22:59:47.025Z",
  "errorCode": "000003",
  "description": "A descriptive or long description of the error"
}

Installation

To install the necessary dependencies, run:

npm install abs-nestjs-http-exception-filter-middleware

Usage with NestJS

  1. Import the HttpExceptionFilterMiddleware into your main.ts:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilterMiddleware } from 'abs-nestjs-exception-filter-middleware';
import { config } from './config';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // use global http exception filter middleware
  app.useGlobalFilters(new HttpExceptionFilterMiddleware());

  await app.listen(config.port);
}
bootstrap();
  1. Extend the ErrorCodes class
import { HttpStatus } from '@nestjs/common';
import { ErrorCodes } from 'abs-nestjs-exception-filter-middleware';

export class CustomErrors extends ErrorCodes {
  public static CUSTOM_ERROR = {
    CODE: '000021',
    STATUS_CODE: HttpStatus.INTERNAL_SERVER_ERROR,
    MESSAGE: 'Something went wrong. Please try again later',
    DESCRIPTION:
      'An internal issue occurred. Either you or the system may have done something wrong. Please try again later or contact support.',
  };

  public static CUSTOM_ERROR_WITH_PARAMS ({ args1, args2 }) {
    CODE: '000021',
    STATUS_CODE: HttpStatus.INTERNAL_SERVER_ERROR,
    MESSAGE: `Passed params ${args1} and ${args2}`,
    DESCRIPTION:
      'An internal issue occurred. Either you or the system may have done something wrong. Please try again later or contact support.',
  }
}
  1. Somewhere in your code, you can import the helper throwExceptionError then use it to throw your Custom Error
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { throwExceptionError } from 'abs-nestjs-exception-filter-middleware';
import { CustomErrors } './custom-errors.constants';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('/error-1')
  someMethod(): string {
    throwExceptionError(CustomErrors.CUSTOM_ERROR);
  }

  @Get('/error-2')
  someMethod(): string {
    throwExceptionError(CustomErrors.CUSTOM_ERROR_WITH_PARAMS({ args1: 'test1', args2: 'test2'}));
  }
}