@nocobase/plugin-error-handler 2.0.0-beta.2 → 2.0.0-beta.21

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.
@@ -8,9 +8,9 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-beta.2",
11
+ "@nocobase/client": "2.0.0-beta.21",
12
12
  "@formily/json-schema": "2.3.7",
13
- "@nocobase/database": "2.0.0-beta.2",
14
- "@nocobase/server": "2.0.0-beta.2",
13
+ "@nocobase/database": "2.0.0-beta.21",
14
+ "@nocobase/server": "2.0.0-beta.21",
15
15
  "lodash": "4.17.21"
16
16
  };
@@ -88,16 +88,48 @@ class PluginErrorHandlerServer extends import_server.Plugin {
88
88
  ctx.status = 400;
89
89
  }
90
90
  );
91
- this.errorHandler.register(
92
- (err) => {
93
- const e = (err == null ? void 0 : err.original) || err;
94
- if ((e == null ? void 0 : e.errno) === 1064) return true;
95
- if ((e == null ? void 0 : e.code) === "42601") return true;
96
- if ((e == null ? void 0 : e.code) === "SQLITE_ERROR" && /syntax error/i.test(e == null ? void 0 : e.message)) {
97
- return true;
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-beta.2",
9
+ "version": "2.0.0-beta.21",
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": "b77a33ee933ae6e09d2d5dce017ca15d8552d57b"
31
+ "gitHead": "3ea30685d9592934ec578c0b5e8def60a7fcc3c2"
32
32
  }