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

@tobes/application-error

v1.0.2

Published

Super simple, bare bones extension of Error to support error codes. A chai plugin to make ApplicationError testing easier is also included.

Readme

ApplicationError

Super simple, bare bones extension of Error to support error codes.

Purpose

When being consumed by a client, service errors that depend on message strings only are very hard to make decisions in code with.

Making those decisions based on Error subclass names puts you in the situation where you are transcribing class names to the client and being pulled in two directions when you name the classes.

Extending Error with ApplicationError provides errors with codes for easy consumption in code and messages for human/programmer logging/debuging/comprehension.

Usage

const { ApplicationError } = require('@tobes/application-error');

// code is required
const appError = new ApplicationError('CODE');

// appError.appcode === 'CODE'

// message and the other Error class arguments are optional
const appError = new ApplicationError('CODE', 'Human message');

// appError.appcode === 'CODE'
// appError.message === 'Human message'

ThrowsCode

A chai plugin to add throwCode to chai expect/should statements

Purpose

Allow testing of ApplicationError throwing code to be precise and test for specific errors without adding all the fragility involved in testing for specific human readable error messages or having to subclass everything.

Usage

const { ThrowCode, ApplicationError } = require('@tobes/application-error');
const chai = require('chai');
const expect = chai.expect;
chai.use( ThrowCode );

describe('.some function', () => {
    it('some test case', () => {
        const throwingFunction = () => { throw new ApplicationError('ERROR_CODE') };
        expect(throwingFunction).to.throwCode(ApplicationError, 'ERROR_CODE');
    });
};

Tests

$ git clone [email protected]:tobespangler/application-error.git
$ cd application-error
$ npm install
$ npm test

 ApplicationError
    #constuctor
      ✓ Error code is set
      ✓ Error code is mandatory
      ✓ Error message is set
      ✓ Error message is not mandatory
      ✓ Parent class is Error
    .toString
      ✓ Contains error name, code and message
      ✓ Contains error name and message and code when code is empty string
      ✓ Contains error name message and code when code is null
      ✓ Contains error name and code when message is empty string
      ✓ Contains error name and code when message is not provided
      ✓ Contains error name message and code when message is null
      ✓ Contains error name and code when message is undefined

  ThrowCode
    ✓ expected code and error received
    ✓ expected code and compatible error received
    ✓ expected code not received
    ✓ expected error class not received
    ✓ expected error class overrides wrong code if both are wrong
    ✓ no error thrown
    ✓ correct error thrown but error class does not have codes
    ✓ negate not allowed


  20 passing (19ms)

----------------------|----------|----------|----------|----------|-------------------|
File                  |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------------|----------|----------|----------|----------|-------------------|
All files             |      100 |      100 |      100 |      100 |                   |
 application_error.js |      100 |      100 |      100 |      100 |                   |
 throw_code.js        |      100 |      100 |      100 |      100 |                   |
----------------------|----------|----------|----------|----------|-------------------|