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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@huds0n/error

v2.0.0-beta1

Published

Extended JS Error

Downloads

118

Readme

Status GitHub Issues GitHub Pull Requests License


📝 Table of Contents

🧐 About

Error Class extending on JavaScript's Error, adding in additional properties, such as: code, severity, handled, ect...

Used throughout the Huds0n modules libary.

✅ List of Features

  • Informative: Adds typed props for code, severity, info, and more.
  • Current: Easily updated or flagged as handled.
  • Lossless: Update history is stored.
  • Typed: Fully integrated with typescript out-of-the-box.
  • Transferable: Built-in methods to JSON stringify and parse.

🏁 Getting Started

Installing

npm i @huds0n/error

🧑‍💻 Basic Usage

Creating an Error

import { Huds0nError } from '@huds0n/error';

// Or with node

const { HudsonError } = require('@huds0n/error');

const exampleError = new Huds0nError(errorProps);

See reference for errorProps

Handling an Error

exampleError.handled(handledProps);

Handled props is an optional object that adds handled info to the error.

Updating an Error

exampleError.update(props);

The new properties are added to the error. Overwritten properties are pushed to the update history, which can be seen on error printing.

Displaying an Error

For concise logging use the toString method.

console.log(exampleError.toString());

/*
  Huds0nError - EXAMPLE_ERROR (MEDIUM - HANDLED)
*/

For detailed information use the print method.

console.log(exampleError.print());

/*
  
  ---------------------------------------------------------------

  Huds0nError - EXAMPLE_ERROR (MEDIUM - HANDLED)
  Info: {
    ...info is stringified here
  }
  HandledInformation: {
    ...if error's handled flag is an object it is stringified here
  }
  UpdateHx: [...array of overwritten error properties with timestamps]
  ...stack trace

  ---------------------------------------------------------------

*/

Transforming an Error

Sometimes may need to convert an error into a Huds0nError, i.e. a catch block. For this, use the static transform method.

try {
  // Some code
} catch (e) {
  const caughtError = Huds0nError.transform(e, errorProps);
}

The transform error converts any type into a Huds0nError. ErrorProps are then merged to create the Huds0nError, with additional information being placed in the info prop. If the error being transformed is already a Huds0nError it is left unchanged with only the info props being merged.

🧑‍🔬 Advanced Usage

Reviving an Error

HudsOnErrors can easily be turned into JSON with the instance method toJSON, then parsed back to a Huds0nError using the static method JSONreviver

const stringifiedError = exampleError.toJSON();

const revivedError = JSON.parse(stringifiedError, Huds0nError.JSONreviver);

📖 Reference

Error Props

| Prop | Required/(Default) | Description | Type | | -------- | :-------------------------: | ----------------------------------------- | -------------------------------------- | | code | ✔ | user defined error code | string or number | | handled | false | whether error has been handle | boolean or object | | info | {} | additional information | object | | message | Message Missing | human-readable error message | string | | name | Huds0nError | error nameuseful for grouping errors | string | | severity | ✔ | severity of error | HIGH, MEDIUM,LOW, or NONE | | stack | (Inherited from JS Error) | trace of error | string |

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

  • Special thanks to my fiance, Arma, who has been so patient with all my extra-curricular work.