@ianwalter/base-error
v6.1.0
Published
A general base Error class that can be extended to create custom Error classes
Downloads
120
Readme
@ianwalter/base-error
A general base Error class that can be extended to create custom Error classes
Installation
npm install @ianwalter/base-error --save
Usage
import BaseError from '@ianwalter/base-error'
// Extend BaseError to create your custom error and optionally pass additional
// data to be included in the error message.
class SomeError extends BaseError {
constructor (details) {
super('Something happened', details)
}
}
// Implementation example:
const someError = new SomeError({ user: 1 })
if (someError instanceof SomeError) {
console.error(someError)
}
/*
Logs an error like:
SomeError: Something happened
{
"user": 1
}
(stacktrace)
*/
License
Hippocratic License - See LICENSE
Created by Ian Walter