UNPKG

858 BJavaScriptView Raw
1const errorMap = {
2 1: '未知错误', // Unknown Error
3 2: '无效参数', // Bad Parameters
4 3: '无此方法', // Method Not Found
5 4: '签名验证失败', // Signature Verification Failed
6 5: '未登录', // Unauthorized
7 6: '账号密码错误', // Wrong Password
8 7: '请求来源非法', // Invalid Referer
9 8: '无效时间', // Invalid Time
10 9: '非法访问', // Access Denied
11 10: '服务内部异常', // Internal Error
12 11: '请求超出接口限额' // Too Many Requests
13}
14
15function 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
24APIException.prototype = Object.create(Error.prototype)
25APIException.prototype.name = 'APIException'
26
27module.exports = APIException