schema-dsl 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -3
- package/README.md +149 -4
- package/STATUS.md +37 -3
- package/changelogs/v1.1.5.md +493 -0
- package/docs/error-handling.md +247 -2
- package/docs/runtime-locale-support.md +27 -0
- package/index.d.ts +77 -2
- package/lib/core/Locale.js +28 -22
- package/lib/core/MessageTemplate.js +30 -21
- package/lib/core/Validator.js +6 -1
- package/lib/errors/I18nError.js +38 -9
- package/lib/locales/en-US.js +13 -3
- package/lib/locales/zh-CN.js +14 -3
- package/lib/validators/CustomKeywords.js +10 -2
- package/package.json +1 -1
package/lib/locales/zh-CN.js
CHANGED
|
@@ -17,6 +17,7 @@ module.exports = {
|
|
|
17
17
|
'conditional.blocked': '账号已被封禁',
|
|
18
18
|
'conditional.notAllowed': '不允许注册',
|
|
19
19
|
|
|
20
|
+
// I18nError - 通用错误消息 (v1.1.1)
|
|
20
21
|
// I18nError - 通用错误消息 (v1.1.1)
|
|
21
22
|
'error.notFound': '找不到{{#resource}}',
|
|
22
23
|
'error.forbidden': '没有权限访问{{#resource}}',
|
|
@@ -26,10 +27,17 @@ module.exports = {
|
|
|
26
27
|
'error.conflict': '操作冲突: {{#reason}}',
|
|
27
28
|
|
|
28
29
|
// I18nError - 账户相关 (v1.1.1)
|
|
29
|
-
|
|
30
|
+
// v1.1.5: 部分使用对象格式示例
|
|
31
|
+
'account.notFound': {
|
|
32
|
+
code: 'ACCOUNT_NOT_FOUND',
|
|
33
|
+
message: '账户不存在'
|
|
34
|
+
},
|
|
30
35
|
'account.inactive': '账户未激活',
|
|
31
36
|
'account.banned': '账户已被封禁',
|
|
32
|
-
'account.insufficientBalance':
|
|
37
|
+
'account.insufficientBalance': {
|
|
38
|
+
code: 'INSUFFICIENT_BALANCE',
|
|
39
|
+
message: '余额不足,当前余额{{#balance}},需要{{#required}}'
|
|
40
|
+
},
|
|
33
41
|
'account.insufficientCredits': '积分不足,当前积分{{#credits}},需要{{#required}}',
|
|
34
42
|
|
|
35
43
|
// I18nError - 用户相关 (v1.1.1)
|
|
@@ -38,7 +46,10 @@ module.exports = {
|
|
|
38
46
|
'user.noPermission': '没有管理员权限',
|
|
39
47
|
|
|
40
48
|
// I18nError - 订单相关 (v1.1.1)
|
|
41
|
-
'order.notPaid':
|
|
49
|
+
'order.notPaid': {
|
|
50
|
+
code: 'ORDER_NOT_PAID',
|
|
51
|
+
message: '订单未支付'
|
|
52
|
+
},
|
|
42
53
|
'order.paymentMissing': '缺少支付信息',
|
|
43
54
|
'order.addressMissing': '缺少收货地址',
|
|
44
55
|
|
|
@@ -90,12 +90,20 @@ class CustomKeywords {
|
|
|
90
90
|
// ajv 默认不支持同步验证中的异步操作
|
|
91
91
|
// 这里我们只能抛出错误提示
|
|
92
92
|
// 真正的异步支持需要 Validator.validateAsync
|
|
93
|
-
|
|
93
|
+
const messageConfig = Locale.getMessage('ASYNC_VALIDATION_NOT_SUPPORTED');
|
|
94
|
+
const errorMessage = typeof messageConfig === 'object' && messageConfig.message
|
|
95
|
+
? messageConfig.message
|
|
96
|
+
: messageConfig;
|
|
97
|
+
throw new Error(errorMessage);
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
// 处理返回值
|
|
97
101
|
if (result === false) {
|
|
98
|
-
|
|
102
|
+
const messageConfig = Locale.getMessage('CUSTOM_VALIDATION_FAILED');
|
|
103
|
+
const errorMessage = typeof messageConfig === 'object' && messageConfig.message
|
|
104
|
+
? messageConfig.message
|
|
105
|
+
: messageConfig;
|
|
106
|
+
validate.errors = [{ message: errorMessage }];
|
|
99
107
|
return false;
|
|
100
108
|
}
|
|
101
109
|
if (typeof result === 'string') {
|