完善了一些异常的i18n
This commit is contained in:
parent
ac944def9e
commit
a2c0c827d6
|
|
@ -16,6 +16,11 @@ const i18ns = [
|
|||
"signatureFailed": "验签失败",
|
||||
"attributesNull": "属性[%{attributes}]不允许为空",
|
||||
"attributesCantUpdate": "属性[%{attributes}]不能更新",
|
||||
"attributesFormatError": "属性[%{attributes}]格式不对,应当是[%{format}]",
|
||||
"attributesTooLong": "属性[%{attributes}]长度过长,最长长度是[%{length}]",
|
||||
"attributesOverMax": "属性[%{attributes}]超过最大值[%{threshold}]",
|
||||
"attributesUnderMin": "属性[%{attributes}]低于最小值[%{threshold}]",
|
||||
"attributesNotInEnumeration": "属性[%{attributes}]不在有效的枚举值当中",
|
||||
"operationUnpermitted": "用户操作权限不足",
|
||||
"dataInvisible": "用户查询权限不足",
|
||||
"unLoggedIn": "用户未登录",
|
||||
|
|
|
|||
|
|
@ -352,11 +352,17 @@ function checkAttributeLegal(schema, entity, data) {
|
|||
case 'char':
|
||||
case 'varchar': {
|
||||
if (typeof data[attr] !== 'string') {
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is not a string`);
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], 'error::attributesFormatError', 'oak-domain', {
|
||||
attribtues: attr,
|
||||
format: 'string',
|
||||
});
|
||||
}
|
||||
const { length } = params;
|
||||
if (length && data[attr].length > length) {
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is too long`);
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], 'error::attributesTooLong', 'oak-domain', {
|
||||
attributes: attr,
|
||||
length,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -367,21 +373,30 @@ function checkAttributeLegal(schema, entity, data) {
|
|||
case 'decimal':
|
||||
case 'money': {
|
||||
if (typeof data[attr] !== 'number') {
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is not a number`);
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], 'error::attributesFormatError', 'oak-domain', {
|
||||
attribtues: attr,
|
||||
format: 'number',
|
||||
});
|
||||
}
|
||||
const { min, max } = params || {};
|
||||
if (typeof min === 'number' && data[attr] < min) {
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is too small`);
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], 'error::attributesUnderMin', 'oak-domain', {
|
||||
attributes: attr,
|
||||
threshold: `${min}`,
|
||||
});
|
||||
}
|
||||
if (typeof max === 'number' && data[attr] > max) {
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is too big`);
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], 'error::attributesOverMax', 'oak-domain', {
|
||||
attributes: attr,
|
||||
threshold: `${max}`,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'enum': {
|
||||
(0, assert_1.default)(enumeration);
|
||||
if (!enumeration.includes(data[attr])) {
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is not in enumeration`);
|
||||
throw new Exception_1.OakInputIllegalException(entity, [attr], 'error::attributesNotInEnumeration');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,9 @@ class OakInputIllegalException extends OakUserException {
|
|||
attributes;
|
||||
entity;
|
||||
constructor(entity, attributes, message, _module, params) {
|
||||
super(message, _module, params);
|
||||
super(message, _module, params || {
|
||||
attributes: attributes.join(','),
|
||||
});
|
||||
this.entity = entity;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ function checkAttributesNotNull(entity, data, attributes, allowEmpty) {
|
|||
}
|
||||
});
|
||||
if (attrs.length > 0) {
|
||||
throw new types_1.OakAttrNotNullException(entity, attrs, '属性不能为空');
|
||||
throw new types_1.OakAttrNotNullException(entity, attrs, 'error::attributesNull');
|
||||
}
|
||||
}
|
||||
exports.checkAttributesNotNull = checkAttributesNotNull;
|
||||
|
|
@ -127,7 +127,7 @@ exports.checkAttributesNotNull = checkAttributesNotNull;
|
|||
function checkAttributesScope(entity, data, attributes) {
|
||||
const attrs = attributes.filter(attr => !data.hasOwnProperty(attr));
|
||||
if (attrs.length > 0) {
|
||||
throw new types_1.OakInputIllegalException(entity, attrs, '多余的属性');
|
||||
throw new types_1.OakInputIllegalException(entity, attrs, 'error::attributesCantUpdate');
|
||||
}
|
||||
}
|
||||
exports.checkAttributesScope = checkAttributesScope;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ const i18ns: I18n[] = [
|
|||
"signatureFailed": "验签失败",
|
||||
"attributesNull": "属性[%{attributes}]不允许为空",
|
||||
"attributesCantUpdate": "属性[%{attributes}]不能更新",
|
||||
"attributesFormatError": "属性[%{attributes}]格式不对,应当是[%{format}]",
|
||||
"attributesTooLong": "属性[%{attributes}]长度过长,最长长度是[%{length}]",
|
||||
"attributesOverMax": "属性[%{attributes}]超过最大值[%{threshold}]",
|
||||
"attributesUnderMin": "属性[%{attributes}]低于最小值[%{threshold}]",
|
||||
"attributesNotInEnumeration": "属性[%{attributes}]不在有效的枚举值当中",
|
||||
"operationUnpermitted": "用户操作权限不足",
|
||||
"dataInvisible": "用户查询权限不足",
|
||||
"unLoggedIn": "用户未登录",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@
|
|||
"signatureFailed": "验签失败",
|
||||
"attributesNull": "属性[%{attributes}]不允许为空",
|
||||
"attributesCantUpdate": "属性[%{attributes}]不能更新",
|
||||
"attributesFormatError": "属性[%{attributes}]格式不对,应当是[%{format}]",
|
||||
"attributesTooLong": "属性[%{attributes}]长度过长,最长长度是[%{length}]",
|
||||
"attributesOverMax": "属性[%{attributes}]超过最大值[%{threshold}]",
|
||||
"attributesUnderMin": "属性[%{attributes}]低于最小值[%{threshold}]",
|
||||
"attributesNotInEnumeration": "属性[%{attributes}]不在有效的枚举值当中",
|
||||
"operationUnpermitted": "用户操作权限不足",
|
||||
"dataInvisible": "用户查询权限不足",
|
||||
"unLoggedIn": "用户未登录",
|
||||
|
|
|
|||
|
|
@ -392,11 +392,17 @@ function checkAttributeLegal<ED extends EntityDict & BaseEntityDict>(
|
|||
case 'char':
|
||||
case 'varchar': {
|
||||
if (typeof (data as ED[keyof ED]['CreateOperationData'])[attr] !== 'string') {
|
||||
throw new OakInputIllegalException(entity, [attr], `${entity as string}: ${attr}'s value "${(data as ED[keyof ED]['CreateOperationData'])[attr]}" is not a string`);
|
||||
throw new OakInputIllegalException(entity, [attr], 'error::attributesFormatError', 'oak-domain', {
|
||||
attribtues: attr,
|
||||
format: 'string',
|
||||
});
|
||||
}
|
||||
const { length } = params!;
|
||||
if (length && (data as ED[keyof ED]['CreateOperationData'])[attr]!.length > length) {
|
||||
throw new OakInputIllegalException(entity, [attr], `${entity as string}: ${attr}'s value "${(data as ED[keyof ED]['CreateOperationData'])[attr]}" is too long`);
|
||||
throw new OakInputIllegalException(entity, [attr], 'error::attributesTooLong', 'oak-domain', {
|
||||
attributes: attr,
|
||||
length,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -407,21 +413,30 @@ function checkAttributeLegal<ED extends EntityDict & BaseEntityDict>(
|
|||
case 'decimal':
|
||||
case 'money': {
|
||||
if (typeof (data as ED[keyof ED]['CreateOperationData'])[attr] !== 'number') {
|
||||
throw new OakInputIllegalException(entity, [attr], `${entity as string}: ${attr}'s value "${(data as ED[keyof ED]['CreateOperationData'])[attr]}" is not a number`);
|
||||
throw new OakInputIllegalException(entity, [attr], 'error::attributesFormatError', 'oak-domain', {
|
||||
attribtues: attr,
|
||||
format: 'number',
|
||||
});
|
||||
}
|
||||
const { min, max } = params || {};
|
||||
if (typeof min === 'number' && (data as ED[keyof ED]['CreateOperationData'])[attr] < min) {
|
||||
throw new OakInputIllegalException(entity, [attr], `${entity as string}: ${attr}'s value "${(data as ED[keyof ED]['CreateOperationData'])[attr]}" is too small`);
|
||||
throw new OakInputIllegalException(entity, [attr], 'error::attributesUnderMin', 'oak-domain', {
|
||||
attributes: attr,
|
||||
threshold: `${min}`,
|
||||
});
|
||||
}
|
||||
if (typeof max === 'number' && (data as ED[keyof ED]['CreateOperationData'])[attr] > max) {
|
||||
throw new OakInputIllegalException(entity, [attr], `${entity as string}: ${attr}'s value "${(data as ED[keyof ED]['CreateOperationData'])[attr]}" is too big`);
|
||||
throw new OakInputIllegalException(entity, [attr], 'error::attributesOverMax', 'oak-domain', {
|
||||
attributes: attr,
|
||||
threshold: `${max}`,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'enum': {
|
||||
assert(enumeration);
|
||||
if (!enumeration.includes((data as ED[keyof ED]['CreateOperationData'])[attr])) {
|
||||
throw new OakInputIllegalException(entity, [attr], `${entity as string}: ${attr}'s value "${(data as ED[keyof ED]['CreateOperationData'])[attr]}" is not in enumeration`);
|
||||
throw new OakInputIllegalException(entity, [attr], 'error::attributesNotInEnumeration');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,7 +258,9 @@ export class OakInputIllegalException<ED extends EntityDict & BaseEntityDict> ex
|
|||
private attributes: string[];
|
||||
private entity: keyof ED;
|
||||
constructor(entity: keyof ED, attributes: string[], message?: string, _module?: string, params?: Record<string, any>) {
|
||||
super(message, _module, params);
|
||||
super(message, _module, params || {
|
||||
attributes: attributes.join(','),
|
||||
});
|
||||
this.entity = entity;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ export function checkAttributesNotNull<ED extends EntityDict, T extends keyof En
|
|||
) as string[];
|
||||
|
||||
if (attrs.length > 0) {
|
||||
throw new OakAttrNotNullException(entity as string, attrs, '属性不能为空');
|
||||
throw new OakAttrNotNullException(entity as string, attrs, 'error::attributesNull');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -149,6 +149,6 @@ export function checkAttributesScope<ED extends EntityDict, T extends keyof Enti
|
|||
) as string[];
|
||||
|
||||
if (attrs.length > 0) {
|
||||
throw new OakInputIllegalException(entity as string, attrs, '多余的属性');
|
||||
throw new OakInputIllegalException(entity as string, attrs, 'error::attributesCantUpdate');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue