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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@geren32/nestjs-error-handler

v1.0.0

Published

Unified error handling layer for NestJS: single response format, error codes for i18n, categories (business/validation/auth/system), safe production logging

Readme

@softdoes/nestjs-error-handler

Unified error handling layer for NestJS: single response format, stable error codes, Prisma-aware mapping, and configurable logging.

Features

  • Single response shape: { success: false, error: { code, category, message?, details?, requestId? }, statusCode }
  • Error categories: business | validation | auth | system
  • Common Prisma client errors mapped automatically
  • Production-safe responses when hideInternalDetails is enabled
  • Configurable logger adapter so logs can go through your app logger

Install

npm i @softdoes/nestjs-error-handler

Peer dependencies: @nestjs/common and @nestjs/core ^10 || ^11.

Setup

import { Module } from '@nestjs/common';
import { ErrorHandlerModule } from '@softdoes/nestjs-error-handler';

import appLogger from './common/logger/logger';

@Module({
  imports: [
    ErrorHandlerModule.register({
      hideInternalDetails: true,
      includeRequestId: true,
      getRequestId: (req) => req.headers?.['x-request-id'] as string | undefined,
      logger: {
        warn: (message, payload) => appLogger.warn(message, payload),
        error: (message, payload) => appLogger.error(message, payload),
      },
    }),
  ],
})
export class AppModule {}

Remove any existing global exception filter so this package stays the single response formatter.

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | hideInternalDetails | boolean | false | When true, internal messages and details are hidden from responses | | includeRequestId | boolean | true | Include error.requestId when available | | getRequestId | (req) => string \| undefined | x-request-id header | Custom request id extractor | | logger | { warn(...), error(...) } | Nest Logger fallback | Custom logger adapter |

The application should decide the value itself, for example hideInternalDetails: config.isProduction.

Throwing errors

import {
  AuthError,
  BusinessError,
  ErrorCodes,
  SystemError,
  ValidationError,
} from '@softdoes/nestjs-error-handler';

throw new BusinessError(ErrorCodes.USER_NOT_FOUND, { httpStatus: 404 });
throw new ValidationError(ErrorCodes.VALIDATION_FAILED, {
  details: { field: 'email', reason: 'invalid' },
});
throw new AuthError(ErrorCodes.INVALID_CREDENTIALS);
throw new SystemError(ErrorCodes.INTERNAL_ERROR, { cause: err });

Prisma errors

The package maps common Prisma errors automatically:

  • P2002 -> UNIQUE_CONSTRAINT (409)
  • P2003 -> FOREIGN_KEY_CONSTRAINT (400)
  • P2025 -> RECORD_NOT_FOUND (404)
  • P2000 -> VALUE_TOO_LONG (400)

Response behavior

When hideInternalDetails is true, the response keeps only code, category, and optionally requestId. For system errors a generic "Internal server error" message is returned.

When hideInternalDetails is false, the response also includes message and details when available.

Notes

  • Use stable code values for frontend i18n.
  • Nest built-in exceptions are normalized to the same response shape.
  • Prisma support is implemented without a hard dependency on Prisma packages.