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

errity

v0.0.11

Published

Error wrapper for JavaScript functions

Downloads

17

Readme

Errity - Elegant Error Handling in JavaScript Functions

Errity lets you catch errors without using try-catch blocks, making your code flatter and more readable. With built-in support for default error handlers and retry mechanisms, Errity provides a solution for error management in both synchronous and asynchronous functions.

Navigation

Installation

npm i errity

Usage

Simple case

  1. Import the errity function
import { errity } from errity;
// or
const { errity } = require('errity');
// or
import { Errity } from 'errity'; // or require
const { errity } = new Errity();
  1. Wrap your function with errity
const brokenFunction = errity(() => {
  // your code
});
  1. Add a second argument, a function that will be called on error
const brokenFunction = errity(
  () => {
    // your code
  },
  (err) => console.log(err.message)
);

More

You can set a default error handler which will be triggered for all wrapped functions that don't have their own error handler:

const { errity } = new Errity({
  defaultErrorCb: (err) => console.log(err.message),
});

const brokenFunction = errity(() => {
  // your code
});

Second argument can be function or object:

const brokenFunction = errity(
  () => {
    // your code
  },
  {
    onError: (err) => console.log(err.message),
  }
);

You can get error logs using the following code:

const { errity, logs } = new Errity({
  logger: true,
});
console.log(logs); // array of error logs

Configuration properties and methods for errity function

  • retryCount - the number of retry attempts when an error occurs (works with both synchronous and asynchronous functions)
  • retryDelay - the delay between retry attempts when an error occurs
  • onRetryError - a function triggered on retry errors (if retryCount is 5, this function will be called 4 times)
  • onError - a function triggered on error (if retryCount is 5, this function will be called once after 4 onRetryError calls)

Configuration properties and methods for Errity class

  • logger - a property responsible for error logging
  • defaultErrorCb - a function that will be called on error if no unique error handler is passed to the errity function

Examples

Here's how you wrote the code before:

const getData = async () => {
  try {
    const response = await fetch("https://getsomedata.com");
    const responseData = await response.json();

    if (responseData.isDisabled) {
      navigate("/example-page");
    }
    setState(responseData);
  } catch (error) {
    showNotify(error.message);
  }
};

Block in block in block... It's ugly! Make it more flat.

const getData = errity(
  async () => {
    const response = await fetch("https://getsomedata.com");
    const responseData = await response.json();

    if (responseData.isDisabled) {
      navigate("/example-page");
    }
    setState(responseData);
  },
  (error) => showNotify(error.message)
);

Or if you set a default error function, you can remove the second (catch) argument:

const getData = errity(async () => {
  const response = await fetch("https://getsomedata.com");
  const responseData = await response.json();

  if (responseData.isDisabled) {
    navigate("/example-page");
  }
  setState(responseData);
});

Links

GitHub, npm