1.2.0 • Published 5 years ago

@itavy/ierror v1.2.0

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

IError

This is a module provides support for some missing features of native errors, working as a drop in replacement for native errors:

  • chain of causes
  • custom information for the error
  • timestamp of the error occurrence
  • serialization and composing back the object from serialization

Instalation

npm install @itavy/ierror

Quick Example

const IError = require('@itavy/ierror').IError;

const err = new IError('test error');
console.log(err);

this will produce:

{ ERROR: test error
    at Object.<anonymous> (/**********/test.js:3:13)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
  name: 'ERROR',
  ts: 1492430124565,
  severity: 'ERROR',
  source: null,
  code: null,
  extra: null }

API

itavy/ierror : object

Kind: global namespace

itavy/ierror.IError

Error struture

Kind: static class of itavy/ierror

new IError(options)

ParamTypeDescription
optionsIErrorLiteralerror info

iError.message : String

Error message

Kind: instance property of IError

iError.name : String

Error name

Kind: instance property of IError
Default: 'ERROR'

iError.ts : Number

Error UNIX timestamp

Kind: instance property of IError
Default: Date.now()

iError.severity : String

Error severity

Kind: instance property of IError
Default: 'ERROR'

iError.source : String

Error source

Kind: instance property of IError
Default: null

iError.code : String

Error code

Kind: instance property of IError
Default: null

iError.extra : *

Error extra information

Kind: instance property of IError
Default: null

iError.origStack : String

Error stack trace

Kind: instance property of IError
Default: null
Read only: true

iError.cause : IError

Error cause

Kind: instance property of IError
Default: null
Read only: true

iError.toJSON() ⇒ IErrorLiteral

get IError literal representation

Kind: instance method of IError
Returns: IErrorLiteral - IError literal representation
Access: public

iError.toString() ⇒ String

get IError json stringify

Kind: instance method of IError
Returns: String - JSON representation of IError
Access: public

iError.hasErrorWithName(name) ⇒ Boolean

Check all cause chain to see if an error with requested name exists

Kind: instance method of IError
Returns: Boolean - true if an error with a name exists
Access: public

ParamTypeDescription
nameStringname of the error to look after

iError.hasErrorWithCode(code) ⇒ Boolean

Check all cause chain to see if an error with requested code exists

Kind: instance method of IError
Returns: Boolean - true if an error with a code exists
Access: public

ParamTypeDescription
codeStringcode of the error to look after

iError.getErrorWithName(name) ⇒ IError | null

Traverse all chain to get error with requested name

Kind: instance method of IError
Returns: IError | null - IError found or null otherwise
Access: public

ParamTypeDescription
nameStringname of the error to look after

iError.getErrorWithCode(code) ⇒ IError | null

Traverse all chain to get error with requested code

Kind: instance method of IError
Returns: IError | null - IError found or null otherwise
Access: public

ParamTypeDescription
codeStringcode of the error to look after

itavy/ierror.rejectIError(request) ⇒ Promise

Rejects with IError

Kind: static method of itavy/ierror
Returns: Promise - rejects with an IError

ParamTypeDescription
requestIErrorLiteral | Error | IErrorerror to reject with

itavy/ierror.resolveIError(request) ⇒ Promise

Resolves with IError

Kind: static method of itavy/ierror
Returns: Promise - resolves with an IError
Access: public

ParamTypeDescription
requestObjecterror to resolve with

itavy/ierror.IErrorLiteral : Object

Kind: static typedef of itavy/ierror
Properties

NameTypeDefaultDescription
messageStringError message
nameString'ERROR'Error name
tsNumberDate.now()Error UNIX timestamp
severityString'ERROR'Error severity
sourceStringError source
codeStringError code
extra*Extra information needed to be held with the error
causeIError | Error | nulloriginal cause which triggered
origStackStringstack of the error this error on chain

Usage

see Example

LICENSE

MIT