0.7.1 • Published 3 years ago

simple-custom-errors v0.7.1

Weekly downloads
17
License
ISC
Repository
github
Last release
3 years ago

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

0.7.1

3 years ago

0.6.5

3 years ago

0.7.0

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.5.1

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.7

4 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago