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

nest-exception

v0.1.4

Published

This package is based on Original [NestJs](https://github.com/nestjs/nest/) Http exceptions. `nest-exception` brings the simplicity and structured approach of NestJS error handling to any Node.js application. This for non NestJs projects.

Readme

nest-exception

This package is based on Original NestJs Http exceptions. nest-exception brings the simplicity and structured approach of NestJS error handling to any Node.js application. This for non NestJs projects.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Installation

To install the package, run:

npm install nest-exception

or with yarn:

yarn add nest-exception

Why nest-exception?

NestJS provides an excellent mechanism for handling exceptions, but it is tightly coupled with the Nest framework. nest-exception bridges the gap by offering a same structured error-handling experience to projects outside of NestJS. It allows you to:

  • Define custom exceptions with meaningful metadata.
  • Maintain consistency in error responses.
  • Improve debugging with detailed error information.

Features

  • Structured Errors: Create exceptions with a clear structure and metadata.
  • Customizable: Easily define custom exceptions tailored to your application needs.
  • Framework Agnostic: Designed for use in any Node.js project.
  • Inspired by NestJS: Brings the familiarity and power of NestJS exceptions to non-NestJS projects.

Usage

Basic Example

const { HttpException, NotFoundException } = require('nest-exception');

// Throwing a general exception
throw new HttpException('An error occurred', 500);

// Throwing a specific exception
throw new NotFoundException('Resource not found');

Custom Exceptions

You can extend the base HttpException class to define custom exceptions:

const { HttpException } = require('nest-exception');

class CustomException extends HttpException {
  constructor(message, statusCode, customData) {
    super(message, statusCode);
    this.customData = customData;
  }
}

throw new CustomException('A custom error occurred', 400, { field: 'value' });

Handling Exceptions

Use a centralized error-handling middleware to catch and respond to exceptions in your application:

const express = require('express');
const { HttpException } = require('nest-exception');

const app = express();

// Middleware to handle exceptions
app.use((err, req, res, next) => {
  if (err instanceof HttpException) {
    return res.status(err.status).json({
      message: err.message,
      statusCode: err.status,
      ...err,
    });
  }

  // Default to 500 for unexpected errors
  res.status(500).json({
    message: 'Internal Server Error',
  });
});

app.listen(3000, () => console.log('Server is running on port 3000'));

Available Exceptions

All exceptions in nest js have.

Contributing

Contributions are welcome! If you find a bug or want to suggest a feature, feel free to create an issue or submit a pull request.