es

error-system

Your custom errors in your JavaScript code!

Showing:

Popularity

Downloads/wk

1.1K

GitHub Stars

51

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

1

Size (min+gzip)

1.2KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

error-system

build status Coverage Status Dependency status Dev Dependency status

NPM js-standard-style

Your custom errors in your JavaScript code!

Inspired by node-errno.

Based on errors in bitcore.

Example

createError

var errorSystem = require('error-system')
var RequestError = errorSystem.createError('RequestError', 'Code: {0} (url: {1})')
var request = require('request')

var url = 'https://github.com/notfound11'
request(url, function (error, response) {
  if (error === null && response.statusCode !== 200) {
    error = new RequestError(response.statusCode, url)
  }

  if (error !== null) {
    // ErrorRequestError: Code: 404 (url: https://github.com/notfound11)
    console.error(error.stack.split('\n')[0])
  }
})

extend

var errorSystem = require('error-system')
var RequestError = errorSystem.extend(Error, [{
  name: 'RequestError',
  message: 'Code: {0} (url: {1})',
  errors: [
    {
      name: 'NotFound',
      message: 'Code: 404 (url: {0})'
    }
  ]
}])
var request = require('request')

var url = 'https://github.com/notfound11'
request(url, function (error, response) {
  if (error === null && response.statusCode !== 200) {
    if (response.statusCode === 404) {
      error = new RequestError.NotFound(url)
    } else if (response.statusCode !== 200) {
      error = new RequestError(response.statusCode, url)
    }
  }

  if (error !== null) {
    // ErrorRequestErrorNotFound: Code: 404 (url: https://github.com/notfound11)
    console.error(error.stack.split('\n')[0])
  }
})

License

Code released under the MIT license.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial