typ

typederror

node module: custom error type creator: throw new CustomError()

Showing:

Popularity

Downloads/wk

1

GitHub Stars

0

Maintenance

Last Commit

9yrs ago

Contributors

0

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

typederror

custom error type creator: throw new CustomError()

installation

$ npm install typederror

usage

var typedError = require('typederror')

var MyError = typedError('MyError', {code: 0x1d107, message: 'Not a winning gamepiece.'})

var e = new MyError()

e.code
// => 0x1d107

e.message
// => 'Not a winning gamepiece.'

e.toString()
// => 'MyError: Not a winning gamepiece.'

It'll give you a stack trace, just like a real Error!

e.stack
// => your normal stack trace-y stuff

It's instanceof Error

e instanceof Error
// => true

You can pass inner error messages!

if (err) {
  throw new MyError('We gots an error!', err);
}
// err is available on the newly thrown error's `.inner` property

api

typedError(name, opts) => TypedError

name should be your the name of your error. By convention, it should be PascalCase and end in Error. opts is an optional object with any of these properties:

  • message: default message for this error type
  • code: value representing this type of error (for example, to map to an existing code set, like HTTP status codes)

Returns a TypedError constructor function.

TypedError() or TypedError(message) or TypedError(inner) or TypedError(message, inner)

Constructor. May be called with or without new keyword.

message is a String. inner is an Error, an error to attach to the inner property. Use when throwing a new error in response to another error.

contributors

jden jason@denizac.org

license

MIT. (c) 2013 Agile Diagnosis hello@agilediagnosis.com. See LICENSE.md

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