1 | const errorMap = {
|
2 | 1: '未知错误',
|
3 | 2: '无效参数',
|
4 | 3: '无此方法',
|
5 | 4: '签名验证失败',
|
6 | 5: '未登录',
|
7 | 6: '账号密码错误',
|
8 | 7: '请求来源非法',
|
9 | 8: '无效时间',
|
10 | 9: '非法访问',
|
11 | 10: '服务内部异常',
|
12 | 11: '请求超出接口限额'
|
13 | }
|
14 |
|
15 | function ApiException (code, message) {
|
16 | if (code instanceof APIException || code instanceof Error) {
|
17 | return code
|
18 | }
|
19 |
|
20 | this.code = code = code || 1
|
21 | this.message = message || errorMap[code] || ''
|
22 | }
|
23 |
|
24 | APIException.prototype = Object.create(Error.prototype)
|
25 | APIException.prototype.name = 'APIException'
|
26 |
|
27 | module.exports = APIException
|