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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@smallwins/err

v2.0.4

Published

Slightly better custom Error

Readme

@smallwins/err

Slightly better custom Errors

  • Same runtime interface: just pass a message to the constructor
  • Respects extends with clean name and stack properties
  • Adds toObject returns a plain object representation
  • Bundles common HTTP error types with a code property
npm i @smallwins/err --save

Bundled Error Types

  • err.Err a base Error type intended for extending
  • err.InternalError has a code property of 500
  • err.DatabaseError has a code property of 500
  • err.NotFoundError has a code property of 404
  • err.NotAuthorizedError has a code property of 403

Usage

Example usage:

var err = require('@smallwins/err')

let notFound = new err.NotFoundError('missing record')
console.log(err.code) // logs 404

Subclass to add additional properties such as code:

var err = require('@smallwins/err')

class CoffeeError extends err.Err {
  constructor(params) {
    super(params)
    this.code = 500
  }
}

let e = new CoffeeError('lactose intolerant')
console.log(e.code) // logs 500

Get a clean representation:

console.log(e.toObject())
// logs {name, code, message, stack}

Extend by requireing error directly:

var Err = require('@smallwins/err/err')

class TerribleError extends Err {
  constructor(msg) {
    super(msg)
    this.extra = 'extra info'
  }
}

var e = new TerribleError('wut')
console.log(e.extra)

Work oldschool without new:

var err = require('@smallwins/err/oldschool')

console.log(err.Err('basic') instanceof Error)
// logs true

console.log(err.NotFound('not found err').toString())
// logs NotFound: not found err

@smallwins/err/oldschool API

Factory functions which return real Error instances:

  • err.Err returns an Err instance
  • err.Internal returns an InternalError instance
  • err.Database returns a DatabaseError instance
  • err.NotFound returns a NotFoundError instance
  • err.NotAuthorized returns a NotAuthorizedError instance

Runtime type checking fully supported. Check the tests.