3.0.0 • Published 5 years ago

smart-error v3.0.0

Weekly downloads
102
License
MIT
Repository
github
Last release
5 years ago

SmartError

Subclass of Node.js Error for unification of errors.

The instance has message and code attributes for recognizing the error type and base info about the Error. The constructor accepts the payload field which is parsed as instance's attributes.

Installation

$ npm install smart-error

Usage

// This will override default Node.js Error
import Error from 'smart-error';

// It throws the catchable error
throw new Error('User already exists in database', 'existing_user', { email: 'test@test.com' });
// The fields are 
//  message -> User already exists in database
//  code -> ERR_EXISTING_USER
//  email -> test@test.com

Classes

Functions

Typedefs

SmartError

Kind: global class

new SmartError(message, code, payload)

Creates new instance of SmartError.

ParamType
messagestring | SmartError | Error | ErrorObject
codestring
payloadObject

smartError.clone() ⇒ SmartError

Clones current instance and creates new one.

Kind: instance method of SmartError

smartError.toJSON(stack) ⇒ Object

Converts the instance to JSON object.

Kind: instance method of SmartError

ParamTypeDefaultDescription
stackbooleanfalseIf true the stack is added in the JSON object.

smartError._getCode(code)

Gets the upper cased error with ERR_ prefix from the code. If the code already has the prefix, the code is not altered.

Kind: instance method of SmartError

ParamType
codestring

smartError._setPayload(payload)

Sets the payload fields as instance fields. Message, code and stack are ignored.

Kind: instance method of SmartError

ParamType
payloadObject

smartError._parsePayload(err) ⇒ Object

Parses the payload from the SmartError instance.

Kind: instance method of SmartError

ParamType
errSmartError

SmartError.register(code, message, payload, description)

Registers the error to the object. The code is accesible as the object's function with message and payload fields.

Kind: static method of SmartError

ParamType
codestring
messagestring
payloadobject
descriptionstring

SmartError.unregister(code)

Removes the error from th object.

Kind: static method of SmartError

ParamType
codestring

register(SmartError, code, message, payload, description)

Registers the error to the SmartError object. The code is accesible as the object's function with message and payload fields.

Kind: global function

ParamTypeDefault
SmartErrorSmartError
codestring
messagestring
payloadObject
descriptionstringnull

unregister(SmartError, code)

Removes the error from the SmartError object.

Kind: global function

ParamType
SmartErrorSmartError
codestring

codes() ⇒ Array.<string>

Gets all registered codes as an array.

Kind: global function

docs() ⇒ DocsObject

Gets the documentation of the registered error.

Kind: global function

_call(code, SmartError)

Calls the registered function.

Kind: global function

ParamType
codestring
SmartErrorSmartError

ErrorObject

Kind: global typedef Properties

NameType
messagestring
codestring
payloadObject

DocsObject

Kind: global typedef

ParamType
code.descriptionstring

Properties

NameType
codeobject
3.0.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago