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

tl-errors

v2.3.1

Published

Error manangement middleware for ExpressJS

Readme

TL Errors

An ExpressJS middleware to handle custom errors.

Requirements:

  • NodeJS 6.x.x

Installation

npm install --save tl-errors

Configuration

The first step is to create your configuration file. Here you can define your custom errors, redirection urls and excluded requests.

This package comes with a default configuration that you can extend or overwrite.

Sample configuration file

const config = {
  // Custom application errors
  errors: [
    // This error will be added to the component errors list
    {
      name: 'EnhanceYourCalmError',
      message: 'Breath in... Breath out...'
      code: 420
    },

    // These errors will overwrite the default errors with new messages
    {
      name: 'BadRequestError',
      message: 'The request could not be understood by the server due to malformed syntax.'
      code: 400
    }, {
      name: 'ConflictError',
      message: 'This document is already registered.',
      code: 409
    }
  ],

   // Application custom error handlers
  handlers: {
    // Handle validations errors with BadRequestError
    'ValidationError': 'BadRequestError',

    // Handle errors with code 11000 with MongoDuplicatedError
    '11000': 'DuplicatedEntityError'
  },

  // Every failed HTTP request to these urls will be terminated
  exclude: /^\/(assets|api)\//i,

  // Redirection urls
  redirect: {
    error: '/error?err=',
    lost: '/lost?url='
  },

  // Function to use for debugging
  debug: err => {
    console.log('START ERROR LOG:', new Date());
    console.log(err);
    console.log('END ERROR LOG:', new Date());
  },

  // Condition to debug an error
  shouldDebug: err => err.code > 399

};

Usage

To use the package you must configure it and then bind it to the express application.

Binding the component

const errors = require('tl-errors');
const express = require('express');
const app = express();

// Configure the module
errors.config(config);

// Register other middlewares
// app.use(...);

// Optionally, use the tl-errors not found (404) middleware
app.use(errors.notFoundMiddleware);

// Lastly, bind the tl-errors handler
app.use(errors.handler);

Using the component


const errors = require('tl-errors');

const { BadRequestError } = errors;

module.exports = (router, db) => {

  const User = db.model('user');

  /**
   * Creates a user.
   */
  router.post('/', async (req, res, next) => {

    try {
      const user = await User.create(req.body);

      if (!user) {
        throw new BadRequestError('The user could not be created');
      }

      res.status(HTTP_CODE_CREATED).json(user._id);
    } catch (err) {
      // Any ValidationError caught here will be handled with BadRequestError.
      // Any error with code 11000 caught here will be handled with
      // DuplicatedEntityError.
      next(err);
    }
  });
}

Every error triggered in a middleware will be caught inside the component.

Documentation

Read the library docs for the methods specification.