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

@verisure-italy/express-error-handler-middleware

v1.9.1

Published

Express error handler middleware with support for domain-specific errors

Downloads

151

Readme

@verisure-italy/express-error-handler-middleware

Express error handler designed to close the pipeline of the monorepo packages with a consistent, typed, and customizable error response format.

Installation

pnpm add @verisure-italy/express-error-handler-middleware

Main Exports

  • errorHandler(config)
  • formatters: formatValidationError, formatAuthenticationError, formatAuthorizationError, formatNotFoundError, formatGenericError
  • type guards: isZodError, isDomainError, isValidationError, isAuthenticationError, isAuthorizationError, isNotFoundError
  • types: ErrorHandlerConfig, ErrorResponse, DomainError

ErrorHandlerConfig

| Field | Type | Required | Description | | --- | --- | --- | --- | | includeStackTrace | boolean | No | Include details.stack in the response | | logErrors | boolean | No | Log the error to console.error | | showDetails | boolean | No | Expose validation details and extra error metadata | | onError | (error, req, res) => void | Promise<void> | No | Side-effect hook for logging or monitoring | | skipError | (error, req) => boolean | No | Skip this handler and delegate to the next one | | formatters | formatter overrides | No | Replace the default formatter for a known error family |

ErrorResponse

| Field | Type | Required | Description | | --- | --- | --- | --- | | error | string | Yes | Human-readable error name | | message | string | Yes | Main error message | | statusCode | number | Yes | HTTP status code | | code | string | Yes | Machine-readable error code | | timestamp | string | Yes | ISO timestamp | | path | string | No | Request path | | details | ErrorDetails | No | Validation errors, stack trace, and custom metadata |

Supported Error Families

| Family | Typical source | Output status | | --- | --- | --- | | Zod validation | Direct ZodError instances | 422 | | Router validation | ValidationError from router middleware | 422 | | Authentication | UnauthorizedError, AuthenticationError | 401 | | Authorization | ForbiddenError and compatible domain errors | 403 | | Not found | NotFoundError | 404 | | Generic domain error | Any error with statusCode and code | Custom | | Generic error | Any other Error | 500 |

Integration Example

import { errorHandler } from '@verisure-italy/express-error-handler-middleware'

app.use(errorHandler({
  logErrors: true,
  showDetails: process.env.NODE_ENV !== 'production',
  includeStackTrace: process.env.NODE_ENV === 'development',
  onError: async (error, req) => {
    console.error('API error', {
      path: req.path,
      method: req.method,
      message: error.message,
    })
  },
}))

Notes

  • Mount it as the last middleware in the Express app.
  • If res.headersSent is already true, the handler delegates to the next error handler.
  • onError is intended for side effects, not for mutating the outgoing payload.