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

make-errors-known

v1.0.1

Published

A lightweight Express error-handling utility for TypeScript apps.

Readme

make-errors-known

A lightweight Express error-handling utility for TypeScript apps.

Overview

This package gives you:

  • a custom AppError class
  • a reusable errorHandler middleware
  • a tryCatch wrapper for async route handlers

Installation

npm install make-errors-known express

API

AppError

Use this when you want to create a request or application error with a status code.

import { AppError } from "make-errors-known";

const user = await findUserById(req.params.id);

if (!user) {
  throw new AppError("User not found", 404);
}

errorHandler

Register this middleware at the end of your Express middleware stack.

import express from "express";
import { errorHandler } from "make-errors-known";

const app = express();

app.use(express.json());

app.use(
  errorHandler({
    customRules: [
      {
        match: (err: any) => err.code === "MONGO_DOWN_ERROR",
        statusCode: 503,
        message: "Database is currently offline. Please try again later.",
      },
    ],
    defaultMessage: "An unexpected internal server error occurred.",
  }),
);

If a rule matches, the middleware responds with the configured status code and message. Otherwise, it falls back to the default response.

tryCatch

tryCatch is meant for async work only. Its job is to catch rejected promises from async route handlers and pass them to Express with next(err).

import { tryCatch, AppError } from "make-errors-known";

app.get(
  "/data",
  tryCatch(async (req, res, next) => {
    const data = await fetchSomeDataFromDatabase();

    if (!data) {
      throw new AppError("Data missing", 404);
    }

    res.status(200).json({
      status: "success",
      data,
    });
  }),
);

This is the intended use case: asynchronous logic that returns a promise.

Why it throws when used synchronously

tryCatch is not designed for synchronous functions. It expects the callback to return a promise and immediately calls .catch() on it.

import { tryCatch } from "make-errors-known";

const badExample = tryCatch((req, res) => {
  return "not a promise";
});

This throws at runtime because the result is a string, not a promise.

Example error:

TypeError: callback(...).catch is not a function

Why this happens:

  • tryCatch calls callback(req, res, next).catch(...)
  • a synchronous function returns a plain value instead of a promise
  • plain values do not have .catch()

So if you are doing async work, tryCatch is useful. If you are doing synchronous work, it should not be used.

Example custom rule

const customRules = [
  {
    match: (err: any) => err.code === "DB_ERROR",
    statusCode: 500,
    message: "Database is currently unavailable.",
  },
];

License

ISC