Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tabcat/code-err
create error instances with a code (and props)
https://github.com/tabcat/code-err
err-code error error-handling
Last synced: 1 day ago
JSON representation
create error instances with a code (and props)
- Host: GitHub
- URL: https://github.com/tabcat/code-err
- Owner: tabcat
- License: mit
- Created: 2022-10-05T15:33:26.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T03:33:50.000Z (8 months ago)
- Last Synced: 2024-10-12T12:21:04.174Z (3 months ago)
- Topics: err-code, error, error-handling
- Language: TypeScript
- Homepage:
- Size: 364 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm](https://img.shields.io/npm/v/code-err?color=darkred&style=flat-square)](https://www.npmjs.com/package/code-err)
# code-err
> create error instances with a code (and props)
> a more intuitive [err-code](https://github.com/IndigoUnited/js-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
```ts
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(message, { code, props })// javascript
new CodeError(message, { code, props })
```## API
### CodeError Class
#### constructor
\\>
(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`