@itavy/ierror
v1.2.0
Published
Error module for @itavy namespace
Downloads
10
Readme
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 : object
- .IError
- new IError(options)
- .message : String
- .name : String
- .ts : Number
- .severity : String
- .source : String
- .code : String
- .extra : *
- .origStack : String
- .cause : IError
- .toJSON() ⇒ IErrorLiteral
- .toString() ⇒ String
- .hasErrorWithName(name) ⇒ Boolean
- .hasErrorWithCode(code) ⇒ Boolean
- .getErrorWithName(name) ⇒ IError | null
- .getErrorWithCode(code) ⇒ IError | null
- .rejectIError(request) ⇒ Promise
- .resolveIError(request) ⇒ Promise
- .IErrorLiteral : Object
- .IError
itavy/ierror.IError
Error struture
Kind: static class of itavy/ierror
- .IError
- new IError(options)
- .message : String
- .name : String
- .ts : Number
- .severity : String
- .source : String
- .code : String
- .extra : *
- .origStack : String
- .cause : IError
- .toJSON() ⇒ IErrorLiteral
- .toString() ⇒ String
- .hasErrorWithName(name) ⇒ Boolean
- .hasErrorWithCode(code) ⇒ Boolean
- .getErrorWithName(name) ⇒ IError | null
- .getErrorWithCode(code) ⇒ IError | null
new IError(options)
| Param | Type | Description | | --- | --- | --- | | options | IErrorLiteral | error 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
| Param | Type | Description | | --- | --- | --- | | name | String | name 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
| Param | Type | Description | | --- | --- | --- | | code | String | code 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
| Param | Type | Description | | --- | --- | --- | | name | String | name 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
| Param | Type | Description | | --- | --- | --- | | code | String | code 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
| Param | Type | Description | | --- | --- | --- | | request | IErrorLiteral | Error | IError | error 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
| Param | Type | Description | | --- | --- | --- | | request | Object | error to resolve with |
itavy/ierror.IErrorLiteral : Object
Kind: static typedef of itavy/ierror
Properties
| Name | Type | Default | Description | | --- | --- | --- | --- | | message | String | | Error message | | [name] | String | 'ERROR' | Error name | | [ts] | Number | Date.now() | Error UNIX timestamp | | [severity] | String | 'ERROR' | Error severity | | [source] | String | | Error source | | [code] | String | | Error code | | [extra] | * | | Extra information needed to be held with the error | | [cause] | IError | Error | null | | original cause which triggered | | [origStack] | String | | stack of the error this error on chain |
Usage
see Example