1.0.5 • Published 2 years ago

@alius/exception v1.0.5

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
2 years ago

Extension of Error class allows chain of errors.

Installation

npm install @alius/exception

Usage

Constructor accepts two parameters (optional): message and cause.

import { Exception } from "@alius/exception";

function foo() {
  throw new Exception("Error in foo");
}

function bar() {
  try {
    foo();
  } catch (err) {
    throw new Exception("Error in bar", err);
  }
}

try {
  bar();
} catch (err) {
  console.log(err);
}

Serialization

Exception object can easily serialized to JSON with JSON.stringify(). Following properties are serialized (if present):

  • name
  • message
  • code
  • data
  • signal
  • cause (recursively). If property value is function - it is executed to acquire actual value.

toObject()

Class has method err.toObject() which returns serialized error object with stack property containing stack trace.

Exception.errSerializer(err, showStack = true)

Static method to serialize any Error object.

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago