slenderr
defines the error object of your own. inherits the Error.prototype. but does not let you perform multiple inheritance.
synopsis
var Slenderr = // defines "CookieParseError"Slenderr// can use "Slenderr.CookieParseError"var err = 'not found response.headers.cookie'console // 'CookieParseError'console // 'not found response.headers.cookie'console // '{"name":"CookieParseError","message":"not found response.headers.cookie"}'
in browser
Slenderr.define(...)
or with browerify.
methods
define(name[, defaultMessage [, defaultOption]])
defines the Constructor and attaches to Slenderr.
- name {String} required error name. this name is camelized automatically.
- defaultMessage {String} optional default error message.
- defaultOption {Object} optional the pair of the properties to add to error.
defined constructors
defined the Constructor is camelized and attaches to Slenderr.
Slenderrvar err = message option
- message {String} optional error message. override default error message.
- option {Object} optional additional properties. override default option.
Slenderr// case 1var err = console // 'CookieParseError'console // 'can not parse cookie'console // 400// case 2var err = 'not found cookie in response.headers' code: 499console // 'not found cookie in response.headers'console // 499
inherits
the constructed error object is inherits from Error.prototype.
Slenderr var err = 'foo is not bar'console // trueconsole // trueconsole // false
stacktrace
...
to JSON string
exports to the JSON string containing your own error object.
Slenderr console// {"code":100,"name":"FooError","message":"bar is not foo"}
test
$ npm test
with browserify and testling
$ npm run testling
tips: defines in the small scope
use call
or apply
{ var errs = {} Slenderrdefine var err = ... ...}
license
MIT