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 })
constructor
<T extends Record<string, any>>
(message?: string, options?: { code?: string, props?: T, name?: string, cause?: unknown })
The error message provided to the constructor
default value: ''
The error code provided to the constructor
default value: ''
The error props provided to the constructor
default value: {}
The error name provided to the constructor
default value: 'CodeError'
The error cause provided to the constructor.
default value: undefined