Skip to content

create Error instances with a code (and props)

License

Notifications You must be signed in to change notification settings

wemeetagain/code-err

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeError

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>(code: string, props?: T extends Record<string, any>)

CodeError Instance

message: string

The error message provided to the constructor

code: string

The error code provided to the constructor

props: T extends Record<string, any>

If undefined in constructor it is an empty record/object {}.

About

create Error instances with a code (and props)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 81.0%
  • JavaScript 19.0%