@nocobase/plugin-error-handler 2.1.0-alpha.7 → 2.1.0-alpha.8

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,7 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.1.0-alpha.7",
12
- "@formily/json-schema": "2.3.7",
13
- "@nocobase/database": "2.1.0-alpha.7",
14
- "@nocobase/server": "2.1.0-alpha.7",
11
+ "@nocobase/client": "2.1.0-alpha.8",
12
+ "@nocobase/server": "2.1.0-alpha.8",
15
13
  "lodash": "4.17.21"
16
14
  };
@@ -13,5 +13,6 @@ export declare class PluginErrorHandlerServer extends Plugin {
13
13
  i18nNs: string;
14
14
  beforeLoad(): void;
15
15
  registerSequelizeValidationErrorHandler(): void;
16
+ registerSQLErrorHandler(): void;
16
17
  load(): Promise<void>;
17
18
  }
@@ -39,7 +39,6 @@ __export(server_exports, {
39
39
  PluginErrorHandlerServer: () => PluginErrorHandlerServer
40
40
  });
41
41
  module.exports = __toCommonJS(server_exports);
42
- var import_json_schema = require("@formily/json-schema");
43
42
  var import_server = require("@nocobase/server");
44
43
  var import_lodash = __toESM(require("lodash"));
45
44
  var import_error_handler = require("./error-handler");
@@ -48,9 +47,10 @@ class PluginErrorHandlerServer extends import_server.Plugin {
48
47
  i18nNs = "error-handler";
49
48
  beforeLoad() {
50
49
  this.registerSequelizeValidationErrorHandler();
50
+ this.registerSQLErrorHandler();
51
51
  }
52
52
  registerSequelizeValidationErrorHandler() {
53
- const findFieldTitle = (instance, path, tFunc, ctx) => {
53
+ const findFieldTitle = (instance, path, ctx) => {
54
54
  if (!instance) {
55
55
  return path;
56
56
  }
@@ -63,9 +63,11 @@ class PluginErrorHandlerServer extends import_server.Plugin {
63
63
  return path;
64
64
  }
65
65
  const field = collection.getField(path);
66
- const fieldOptions = import_json_schema.Schema.compile(field == null ? void 0 : field.options, { t: tFunc });
66
+ const fieldOptions = field == null ? void 0 : field.options;
67
67
  const title = import_lodash.default.get(fieldOptions, "uiSchema.title", path);
68
- return title;
68
+ const re = /{{\s*t\(\s*(['"`])([^'"`]+)\1\s*\)\s*}}/g;
69
+ const parsed = re.exec(title);
70
+ return (parsed == null ? void 0 : parsed[2]) || title;
69
71
  };
70
72
  this.errorHandler.register(
71
73
  (err) => {
@@ -76,7 +78,7 @@ class PluginErrorHandlerServer extends import_server.Plugin {
76
78
  ctx.body = {
77
79
  errors: err.errors.map((err2) => {
78
80
  const t = ctx.i18n.t;
79
- const title = findFieldTitle(err2.instance, err2.path, t, ctx);
81
+ const title = findFieldTitle(err2.instance, err2.path, ctx);
80
82
  return {
81
83
  message: t(err2.type, {
82
84
  ns: this.i18nNs,
@@ -88,6 +90,8 @@ class PluginErrorHandlerServer extends import_server.Plugin {
88
90
  ctx.status = 400;
89
91
  }
90
92
  );
93
+ }
94
+ registerSQLErrorHandler() {
91
95
  const unwrapSqlError = (error) => {
92
96
  var _a;
93
97
  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;
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.1.0-alpha.7",
9
+ "version": "2.1.0-alpha.8",
10
10
  "license": "Apache-2.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": "fe825ef778c0d9a941e8517d6443ffc012238391"
31
+ "gitHead": "eda3bfb9df40d4394905e178f1c5331adbec4e76"
32
32
  }