1.1.11 • Published 4 years ago

error-deets v1.1.11

Weekly downloads
111
License
Apache-2.0
Repository
github
Last release
4 years ago

error-deets

npm license action-ci NPM

An extension of vanilla JS errors, that adds two fields:

  • code
  • details

There are a few good reasons to add these fields to a standard error object.

  1. Resuable error objects were few and far in-between in the author's experience with build complex nodejs projects.

  2. custom errors, that extend the base error object, while a nobel thought, are too much work for a single use error objects. When absolutely needed, the .code property, set to a unique value suffices.

  3. In most cases of error, passing an error message with some details from the execution context suffices to provide debuggable hints. Further, using logging solutions like winston, it's easy to log these to any log collector. log.error(err.message, err.details);

Ooh, and this is developed in TypeScript, because it rocks!

Installation

npm install error-deets

Usage

Throwing an error

import { ErrorDeets as Error } from 'error-deets';

throw new Error(`a unique error message`, {
  details: {
    some: 'object with details'
  },
  code: 'StringOrNumOrTypeScriptEnum'
});

Catching and logging an error

try {
  someFunThatThrow();
} catch (err) {
  log.error(err.message, err.details);
}

Development Tooling

License

Apache-2.0

Code of Conduct

This project is released with a Contributor Code of Conduct. By participating, you agree to abide by its terms.

Support

Bugs, PRs, comments, suggestions welcomed!

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

7 years ago