@nocobase/plugin-error-handler 2.0.0-alpha.65 → 2.0.0-alpha.67
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/externalVersion.js +3 -3
- package/dist/server/server.js +54 -9
- package/package.json +2 -2
package/dist/externalVersion.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.0.0-alpha.
|
|
11
|
+
"@nocobase/client": "2.0.0-alpha.67",
|
|
12
12
|
"@formily/json-schema": "2.3.7",
|
|
13
|
-
"@nocobase/database": "2.0.0-alpha.
|
|
14
|
-
"@nocobase/server": "2.0.0-alpha.
|
|
13
|
+
"@nocobase/database": "2.0.0-alpha.67",
|
|
14
|
+
"@nocobase/server": "2.0.0-alpha.67",
|
|
15
15
|
"lodash": "4.17.21"
|
|
16
16
|
};
|
package/dist/server/server.js
CHANGED
|
@@ -88,16 +88,48 @@ class PluginErrorHandlerServer extends import_server.Plugin {
|
|
|
88
88
|
ctx.status = 400;
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
91
|
+
const unwrapSqlError = (error) => {
|
|
92
|
+
var _a;
|
|
93
|
+
return ((_a = error == null ? void 0 : error.original) == null ? void 0 : _a.parent) ?? (error == null ? void 0 : error.parent) ?? (error == null ? void 0 : error.original) ?? error;
|
|
94
|
+
};
|
|
95
|
+
const isSqlSyntaxError = (error) => {
|
|
96
|
+
const err = unwrapSqlError(error);
|
|
97
|
+
if (!err) {
|
|
99
98
|
return false;
|
|
100
|
-
}
|
|
99
|
+
}
|
|
100
|
+
const message = typeof err.message === "string" ? err.message : "";
|
|
101
|
+
if ((err == null ? void 0 : err.errno) === 1064) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if ((err == null ? void 0 : err.code) === "42601") {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
if ((err == null ? void 0 : err.code) === "SQLITE_ERROR" && /syntax error/i.test(message)) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
};
|
|
112
|
+
const isSqlReferenceError = (error) => {
|
|
113
|
+
const err = unwrapSqlError(error);
|
|
114
|
+
if (!err) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const message = typeof err.message === "string" ? err.message : "";
|
|
118
|
+
if ([1054, 1051, 1146, 1052].includes(err == null ? void 0 : err.errno)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (["42703", "42P01", "42702"].includes(err == null ? void 0 : err.code)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (/(unknown column|no such column|has no column named|no such table|unknown table|ambiguous column)/i.test(
|
|
125
|
+
message
|
|
126
|
+
)) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
};
|
|
131
|
+
this.errorHandler.register(
|
|
132
|
+
(err) => isSqlSyntaxError(err),
|
|
101
133
|
(err, ctx) => {
|
|
102
134
|
ctx.body = {
|
|
103
135
|
errors: [
|
|
@@ -109,6 +141,19 @@ class PluginErrorHandlerServer extends import_server.Plugin {
|
|
|
109
141
|
ctx.status = 500;
|
|
110
142
|
}
|
|
111
143
|
);
|
|
144
|
+
this.errorHandler.register(
|
|
145
|
+
(err) => isSqlReferenceError(err),
|
|
146
|
+
(err, ctx) => {
|
|
147
|
+
ctx.body = {
|
|
148
|
+
errors: [
|
|
149
|
+
{
|
|
150
|
+
message: "Invalid SQL column or table reference"
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
};
|
|
154
|
+
ctx.status = 400;
|
|
155
|
+
}
|
|
156
|
+
);
|
|
112
157
|
}
|
|
113
158
|
async load() {
|
|
114
159
|
this.app.use(this.errorHandler.middleware(), { after: "i18n", tag: "errorHandler", before: "cors" });
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"description.ru-RU": "Обработка ошибок и исключений приложения.",
|
|
7
7
|
"description": "Handling application errors and exceptions.",
|
|
8
8
|
"description.zh-CN": "处理应用程序中的错误和异常。",
|
|
9
|
-
"version": "2.0.0-alpha.
|
|
9
|
+
"version": "2.0.0-alpha.67",
|
|
10
10
|
"license": "AGPL-3.0",
|
|
11
11
|
"main": "./dist/server/index.js",
|
|
12
12
|
"homepage": "https://docs.nocobase.com/handbook/error-handler",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
29
29
|
"directory": "packages/plugin-error-handler"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "1fa998002c2e78c777fb4134799f15ea0f4e6cea"
|
|
32
32
|
}
|