Skip to content

Commit 98f8d47

Browse files
authored
add english translation
1 parent 12062df commit 98f8d47

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,39 @@
55
[![npm downloads](https://img.shields.io/npm/dm/coa-error.svg?style=flat-square)](http://npm-stat.com/charts.html?package=coa-error)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/coajs/coa-error/pulls)
77

8-
COA 框架基础错误类,用于统一化错误提示
8+
English | [简体中文](README.zh-CN.md)
99

10-
### 安装
10+
Basic Error Library for coajs, used to unify error messages
11+
12+
### Install
1113

1214
```shell
1315
yarn add coa-error
1416
```
1517

16-
### 使用示例
18+
### Example
1719

1820
```typescript
1921
import { CoaError } from 'coa-error'
2022

21-
// 定义并抛出一个新的错误
22-
throw new CoaError('User.UserAgeInvaild', '用户年龄错误')
23+
// Define and throw a new error
24+
throw new CoaError('User.UserAgeInvaild', 'User age error')
2325

24-
// 使用静态方法抛出(可以当做一个语法糖)
25-
CoaError.throw('User.UserAgeInvaild', '用户年龄错误')
26+
// Thrown using a static method (can be used as a syntax sugar)
27+
CoaError.throw('User.UserAgeInvaild', 'User age error')
2628

27-
// 也可以使用message方法,仅仅提示不在stdio显示(由coa上层框架控制,框架外部调用等同于throw)
28-
CoaError.message('User.UserAgeInvaild', '用户年龄错误')
29+
// You can also use the message method, which only prompts but does not display in stdio (controlled by the coa upsteam framework, other calls are equivalent to throw)
30+
CoaError.message('User.UserAgeInvaild', 'User age error')
2931
```
3032

31-
### 数据结构
33+
### Data structure
3234

33-
COA 错误要求必须定义如下统一参数:
35+
coa error requires that the following uniform parameters must be defined:
3436

35-
- **code** 错误代码,
36-
- **message** 错误消息
37+
- **code** error code
38+
- **message** error message
3739

38-
类定义如下
40+
The class is defined as follows:
3941

4042
```typescript
4143
class CoaError extends Error {

README.zh-CN.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# coa-error
2+
3+
[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)
4+
[![npm version](https://img.shields.io/npm/v/coa-error.svg?style=flat-square)](https://www.npmjs.org/package/coa-error)
5+
[![npm downloads](https://img.shields.io/npm/dm/coa-error.svg?style=flat-square)](http://npm-stat.com/charts.html?package=coa-error)
6+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/coajs/coa-error/pulls)
7+
8+
[English](README.md) | 简体中文
9+
10+
COA 框架基础错误类,用于统一化错误提示
11+
12+
### 安装
13+
14+
```shell
15+
yarn add coa-error
16+
```
17+
18+
### 使用示例
19+
20+
```typescript
21+
import { CoaError } from 'coa-error'
22+
23+
// 定义并抛出一个新的错误
24+
throw new CoaError('User.UserAgeInvaild', '用户年龄错误')
25+
26+
// 使用静态方法抛出(可以当做一个语法糖)
27+
CoaError.throw('User.UserAgeInvaild', '用户年龄错误')
28+
29+
// 也可以使用message方法,仅仅提示但不在stdio显示(由coa上层框架控制,其他方式调用等同于throw)
30+
CoaError.message('User.UserAgeInvaild', '用户年龄错误')
31+
```
32+
33+
### 数据结构
34+
35+
COA 错误要求必须定义如下统一参数:
36+
37+
- **code** 错误代码
38+
- **message** 错误消息
39+
40+
类定义如下:
41+
42+
```typescript
43+
class CoaError extends Error {
44+
name = 'CoaError'
45+
46+
code: string
47+
stdout: boolean
48+
49+
constructor(code: string, message: string, stdout: boolean = true) {
50+
super(message)
51+
this.code = code
52+
this.stdout = stdout
53+
}
54+
55+
static message(code: string, message: string): never {
56+
throw new CoaError(code, message, false)
57+
}
58+
59+
static throw(code: string, message: string): never {
60+
throw new CoaError(code, message)
61+
}
62+
}
63+
```

0 commit comments

Comments
 (0)