@tachybase/module-error-handler 1.3.25 → 1.4.0
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/dist/constants.d.ts +5 -0
- package/dist/constants.js +39 -0
- package/dist/externalVersion.js +1 -1
- package/dist/locale/en_US.json +5 -0
- package/dist/locale/zh_CN.json +5 -0
- package/dist/server/error-handler.js +15 -2
- package/package.json +2 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
DB_ERROR_MAP: () => DB_ERROR_MAP,
|
|
21
|
+
NAMESPACE: () => NAMESPACE
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
|
24
|
+
const DB_ERROR_MAP = [
|
|
25
|
+
{ pattern: /value too long for type character varying/i, code: "ERR_VALUE_TOO_LONG" },
|
|
26
|
+
{ pattern: /relation .* does not exist/i, code: "ERR_RELATION_NOT_EXIST" },
|
|
27
|
+
{ pattern: /duplicate key value violates unique constraint/i, code: "ERR_DUPLICATE_KEY" },
|
|
28
|
+
{
|
|
29
|
+
pattern: /must provide filter or filterByTk for update call, or set forceUpdate to true/i,
|
|
30
|
+
code: "ERR_MISSING_FILTER_UPDATE"
|
|
31
|
+
},
|
|
32
|
+
{ pattern: /invalid input syntax for type timestamp with time zone/i, code: "ERR_INVALID_TIMESTAMP" }
|
|
33
|
+
];
|
|
34
|
+
const NAMESPACE = "@tachybase/module-error-handler";
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
DB_ERROR_MAP,
|
|
38
|
+
NAMESPACE
|
|
39
|
+
});
|
package/dist/externalVersion.js
CHANGED
package/dist/locale/en_US.json
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ERR_DUPLICATE_KEY": "Duplicate data detected, please check and resubmit",
|
|
3
|
+
"ERR_INVALID_TIMESTAMP": "Invalid date format, please correct according to the instructions",
|
|
4
|
+
"ERR_MISSING_FILTER_UPDATE": "Cannot update: please try again later or contact the administrator",
|
|
5
|
+
"ERR_RELATION_NOT_EXIST": "The database table does not exist, please contact the administrator",
|
|
6
|
+
"ERR_VALUE_TOO_LONG": "Content length or quantity exceeds the limit, please adjust accordingly",
|
|
2
7
|
"Validation error": "{{field}} validation error",
|
|
3
8
|
"notNull Violation": "{{field}} cannot be null",
|
|
4
9
|
"notNull violation": "notNull violation",
|
package/dist/locale/zh_CN.json
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ERR_DUPLICATE_KEY": "数据重复,请检查后再提交",
|
|
3
|
+
"ERR_INVALID_TIMESTAMP": "日期格式有误,请根据提示修正。",
|
|
4
|
+
"ERR_MISSING_FILTER_UPDATE": "无法更新:请稍后再试或联系管理员",
|
|
5
|
+
"ERR_RELATION_NOT_EXIST": "系统数据表不存在,请联系管理员",
|
|
6
|
+
"ERR_VALUE_TOO_LONG": "内容长度或数量超出限制,请适当调整",
|
|
2
7
|
"Validation error": "{{field}} 字段规则验证失败",
|
|
3
8
|
"notNull violation": "{{field}} 字段不能为空",
|
|
4
9
|
"unique violation": "{{field}} 字段值是唯一的"
|
|
@@ -20,6 +20,7 @@ __export(error_handler_exports, {
|
|
|
20
20
|
ErrorHandler: () => ErrorHandler
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(error_handler_exports);
|
|
23
|
+
var import_constants = require("../constants");
|
|
23
24
|
class ErrorHandler {
|
|
24
25
|
constructor() {
|
|
25
26
|
this.handlers = [];
|
|
@@ -31,12 +32,24 @@ class ErrorHandler {
|
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
defaultHandler(err, ctx) {
|
|
35
|
+
let code = err.code;
|
|
36
|
+
if (!code && err.message) {
|
|
37
|
+
for (const { pattern, code: mappedCode } of import_constants.DB_ERROR_MAP) {
|
|
38
|
+
if (pattern.test(err.message)) {
|
|
39
|
+
code = mappedCode;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
34
44
|
ctx.status = err.statusCode || err.status || 500;
|
|
35
45
|
ctx.body = {
|
|
36
46
|
errors: [
|
|
37
47
|
{
|
|
38
|
-
message:
|
|
39
|
-
|
|
48
|
+
message: ctx.i18n.t(`${code || "unknown"}`, {
|
|
49
|
+
defaultValue: err.message,
|
|
50
|
+
ns: import_constants.NAMESPACE
|
|
51
|
+
}),
|
|
52
|
+
code
|
|
40
53
|
}
|
|
41
54
|
]
|
|
42
55
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/module-error-handler",
|
|
3
3
|
"displayName": "Error handler",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "Handling application errors and exceptions.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"System management"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@tego/server": "*",
|
|
17
17
|
"lodash": "4.17.21",
|
|
18
18
|
"supertest": "^7.1.3",
|
|
19
|
-
"@tachybase/client": "1.
|
|
19
|
+
"@tachybase/client": "1.4.0"
|
|
20
20
|
},
|
|
21
21
|
"description.zh-CN": "处理应用程序中的错误和异常。",
|
|
22
22
|
"displayName.zh-CN": "错误处理器",
|