create error instances with a code (and props)
a more intuitive err-code
Extends the builtin Error class with .code
and .props
properties for better error handling.
npm install code-err
import { CodeError } from 'code-err'
const message = 'this is an error message'
const code = 'THIS_IS_AN_ERROR_CODE'
interface Props { ... }
const props: Props = { ... }
// typescript without props
new CodeError(message, code)
// typescript with props
new CodeError<Props>(message, code, props)
// javascript
new CodeError(message, code, props)
The error message provided to the constructor
The error code provided to the constructor
If undefined in constructor it is an empty record/object {}
.