@cdellacqua/serializable-error

Custom error class that supports JSON serialization and concatenation

Usage no npm install needed!

<script type="module">
  import cdellacquaSerializableError from 'https://cdn.skypack.dev/@cdellacqua/serializable-error';
</script>

README

serializable-error

Custom error class that supports JSON serialization and concatenation

NPM Package

npm install @cdellacqua/serializable-error

Full documentation:

Highlights

Keep track of what caused the error

try {
    someFunctionThatThrows();
} catch (err) {
    // some error handling logic
    // ...
    throw new SerializableError('something more specific about the current exception', err);
}

Exception logging

try {
    someFunctionThatThrows();
} catch (err) {
    logger.log(SerializableError.from(err));
    // or, if it only accepts strings
    logger.log(JSON.stringify(SerializableError.from(err)));
    throw err;
}