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

@hiprax/errors

v0.1.1

Published

A modular error handling solution for Express.js applications.

Readme

@hiprax/errors

A small, typed, framework-agnostic error toolkit tailored for Express.js apps:

  • Custom Error class with statusCode and statusText
  • Production-ready error middleware for Express
  • Common error mapper for popular libraries (JWT, Axios, validation, etc.)
  • Async wrapper/decorator catchAsync for safe handlers and controllers
  • HTTP error factories for concise and consistent error creation
  • TypeScript first with ESM/CJS builds and .d.ts types

Install

npm install @hiprax/errors

Requires Node >= 18.12.

Quick start

import express from "express";
import {
  errorMiddleware,
  ErrorHandler,
  catchAsync,
  httpErrors,
} from "@hiprax/errors";

const app = express();

app.get(
  "/users/:id",
  catchAsync(async (req, res) => {
    if (req.params.id === "0") {
      throw httpErrors.notFound("User not found");
    }
    res.json({ id: req.params.id });
  })
);

// Always last
app.use(errorMiddleware);

API

class ErrorHandler(message?: string, statusCode?: number)

  • message: defaults to "Something went wrong! Please try again"
  • statusCode: defaults to 500, unknown codes normalize to 500
  • .statusCode: number and .statusText?: string are set based on a predefined map

Example:

throw new ErrorHandler("Not allowed", 403);

errorMiddleware(err, req, res, next)

Express error middleware that:

  • Normalizes errors using handleCommonErrors
  • Maps popular codes like Mongo duplicate key (11000), CSRF, common network codes
  • Avoids writing after headersSent
  • Returns JSON: { success, message, statusCode, statusText, stack? } (stack in non-production only)

Register as the last middleware:

app.use(errorMiddleware);

handleCommonErrors(err)

Maps common libraries/framework errors to ErrorHandler:

  • CastError, ValidationError, JsonWebTokenError, TokenExpiredError, AxiosError, SyntaxError, ZodError
  • Pass-throughs message/statusCode where provided, else defaults to 500

catchAsync(fnOrClass)

Dual-purpose utility:

  • Wrap a single handler to pass thrown/rejected errors to next() and prevent duplicate next() calls
  • Use as a class decorator to wrap all prototype methods of an Express controller
router.get(
  "/posts",
  catchAsync(async (req, res) => {
    const posts = await listPosts();
    res.json(posts);
  })
);

@catchAsync
class UserController {
  async getUser(req: express.Request, res: express.Response) {
    res.json({ id: req.params.id });
  }
}

HTTP error factories (namespaced)

Convenience helpers that return ErrorHandler instances with sensible defaults:

import { httpErrors } from "@hiprax/errors";

throw httpErrors.notFound();
throw httpErrors.forbidden("Only admins can do that");

TypeScript and builds

  • ESM and CJS builds with an exports map
  • Full type declarations
  • Marked as sideEffects: false for optimal tree-shaking

Testing

This package ships with Jest tests exercising all modules. To run locally:

npm test

Contributing

Issues and PRs are welcome. Please include tests and keep the API surface small and focused.

License

MIT © Hiprax