# coa-error

> error component for coa

Latest version **1.5.2** (published 2021-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install coa-error
pnpm add coa-error
yarn add coa-error
bun add coa-error
```

## 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.5.2 |
| Published | 2021-05-03 |
| First published | 2020-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Aex |
| Maintainers | adaex |
| Keywords | coajs, coa, coa-error, error, die |

## Links

- npm: https://www.npmjs.com/package/coa-error
- Repository: https://github.com/coajs/coa-error
- Homepage: https://github.com/coajs
- npm.io page: https://npm.io/package/coa-error

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.5.2 (latest) — 2021-05-03
- 1.5.1 — 2021-05-03
- 1.5.0 — 2021-05-03
- 1.1.3 — 2021-03-12
- 1.1.2 — 2020-11-11
- 1.1.1 — 2020-11-10
- 1.0.5 — 2020-11-10
- 1.0.4 — 2020-05-24
- 1.0.3 — 2020-05-23
- 1.0.2 — 2020-05-23
- 1.0.1 — 2020-05-22

## README

# coa-error

[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)
[![npm version](https://img.shields.io/npm/v/coa-error.svg?style=flat-square)](https://www.npmjs.org/package/coa-error)
[![npm downloads](https://img.shields.io/npm/dm/coa-error.svg?style=flat-square)](http://npm-stat.com/charts.html?package=coa-error)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/coajs/coa-error/pulls)

COA框架基础错误类，用于统一化错误提示

### 安装
```shell
yarn add coa-error
```

### 使用示例

```typescript
import { CoaError } from 'coa-error'


// 定义并抛出一个新的错误
throw new CoaError('User.UserAgeInvaild','用户年龄错误')

// 使用静态方法抛出（可以当做一个语法糖）
CoaError.throw('User.UserAgeInvaild','用户年龄错误')

// 也可以使用message方法，仅仅提示不在stdio显示（由coa上层框架控制，框架外部调用等同于throw）
CoaError.message('User.UserAgeInvaild','用户年龄错误')

```

### 数据结构

COA错误要求必须定义如下统一参数：
- **code** 错误代码，
- **message** 错误消息

类定义如下

```typescript
class CoaError extends Error {
  name = 'CoaError'

  code: string
  stdout: boolean

  constructor (code: string, message: string, stdout: boolean = true) {
    super(message)
    this.code = code
    this.stdout = stdout
  }

  static message (code: string, message: string): never {
    throw new CoaError(code, message, false)
  }

  static throw (code: string, message: string): never {
    throw new CoaError(code, message)
  }
}
```

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