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

simple-custom-errors

v0.7.1

Published

Simple Custom Error creating via JavaScript for better error handling

Downloads

9

Readme

Simple Custom Errors for NodeJS

Caution This library is created alongside some private projects. Because of this,some functionality can be changed if it doesn't work easy enough Of course, everyone is more than welcome to help or create issues!

Description

This simple Node.js package is used for creating custom errors for better error handling in Node.js. It supports custom error codes, descriptions and variables. This along with some useful API formatters. It's perfect for error handling and also has some easy to use middleware.

Installation and Usage

To install the custom errors package, simply install via npm or yarn

npm install --save simple-custom-errors

Setup and usage of the custom errors package follows the same principle.

import SimpleCustomErrors from 'simple-custom-errors';

SimpleCustomErrors.createError('FooError', [
  {
    code: 'Bar',
    description: 'Bar \'{{foo}}\'',
    details: [
      'foo'
    ],
  }
]);

throw new CustomErrors.Errors.FooError('FooError', {foo: 'bar'});

Documentation

Creating an error

Creating an error can be done by using the createError(type, errorList = []) function.

Example

import SimpleCustomErrors from 'simple-custom-errors';

SimpleCustomErrors.createError("ErrorName", [
  {
    code: 'ErrorCode',
    description: 'Error description with {{details}}',
    details: [
      'details'
    ],
  }
])

Using a custom error

When an error is created, it's time to use such an error. This can be done in two ways.

Example

// Use the CustomError variable
import SimpleCustomErrors from 'simple-custom-errors';
throw new SimpleCustomErrors.Errors.ErrorName('ErrorCode', { variable: 'foo' });

// Use the Errors directly
import { Errors } from 'simple-custom-errors';
throw new Errors.ErrorName('ErrorCode', { variable: 'foo' });

This library is a work in progress, there isn't much more functionality than this...

Examples

There are some examples in the 'examples' directory. Feel free to take a look!

Support

If you're having any problems or want some new features, please raise an issue!

This README is a work in progess