# @incpad/error-handle

> ```$xslt const ErrorHandle = require('./packages/error-handle'); const list=[ { code: 1001, msg: 'Path not valid', name: 'PathNotValid', } ] const ErrorHandleInstance=new ErrorHandle()

Latest version **1.0.26** (published 2019-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @incpad/error-handle
pnpm add @incpad/error-handle
yarn add @incpad/error-handle
bun add @incpad/error-handle
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.26 |
| Published | 2019-02-18 |
| First published | 2019-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 35 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | yixuankeer |

## Links

- npm: https://www.npmjs.com/package/@incpad/error-handle
- npm.io page: https://npm.io/package/@incpad/error-handle

## Dependencies (2)

- [@incpad/base-tool](https://npm.io/package/@incpad/base-tool.md) ^1.0.26
- [@incpad/validator](https://npm.io/package/@incpad/validator.md) ^0.0.27

## Recent versions

- 1.0.26 (latest) — 2019-02-18
- 1.0.25 — 2019-02-13

## README

### Usage

```$xslt
    const ErrorHandle = require('./packages/error-handle');
    const list=[
        {
            code: 1001,
            msg: 'Path not valid',
            name: 'PathNotValid',
        }
    ]
    const ErrorHandleInstance=new ErrorHandle()
    ErrorHandleInstance.initCustomErrorWithObject(list)
```
可以选择使用code或者name去触发一个error，使用如下方式触发：

```$xslt
ErrorHandleInstance.throwErrorByName("PathNotValid")
ErrorHandleInstance.throwErrorByCode(1001)
```
在错误定义时可选属性为handleFunc，传入一个函数，该函数会在错误触发之前调用
```$xslt
{
        code: 1001,
        msg: 'Path not valid',
        name: 'PathNotValid',
        handleFunc:e=>{
            //send error to sentry
        }
}
```

---
_Source: https://npm.io/package/@incpad/error-handle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
