@alius/exception
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i @alius/exception

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

16.1 kB

Total Files

7

Last publish

Collaborators

  • alius