New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

smart-error

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-error

Subclass of Node.js Error for unification of errors.

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
1
Created
Source

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

SmartError

Functions

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.

unregister(SmartError, code)

Removes the error from the SmartError object.

codes()Array.<string>

Gets all registered codes as an array.

docs()DocsObject

Gets the documentation of the registered error.

_call(code, SmartError)

Calls the registered function.

Typedefs

ErrorObject
DocsObject

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

Keywords

error

FAQs

Package last updated on 30 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts