3.0.1 • Published 1 year ago

code-err v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

npm

code-err

create error instances with a code (and props) a more intuitive err-code

Description

Extends the builtin Error class with .code and .props properties for better error handling.

Install

npm:

npm install code-err

Import

ESM

import { CodeError } from 'code-err'

Usage

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 })

API

CodeError Class

constructor \<T extends Record\<string, any>> (message?: string, options?: { code?: string, props?: T, name?: string, cause?: unknown })

CodeError Instance

readonly message: string

The error message provided to the constructor

default value: ''

readonly code: string

The error code provided to the constructor

default value: ''

readonly props: T

The error props provided to the constructor

default value: {}

readonly name: string

The error name provided to the constructor

default value: CodeError

readonly cause: unknown

The error cause provided to the constructor.

default value: undefined

3.0.1

1 year ago

3.0.0

1 year ago

2.0.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago