befly 3.15.26 → 3.15.27

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.
@@ -1,4 +1,5 @@
1
1
  import { join } from "node:path";
2
+ import { CoreError } from "./types/coreError";
2
3
  import { importDefault } from "./utils/importDefault";
3
4
  import { mergeAndConcat } from "./utils/mergeAndConcat";
4
5
  /** 默认配置 */
@@ -74,7 +75,12 @@ const defaultOptions = {
74
75
  };
75
76
  export async function loadBeflyConfig(nodeEnv) {
76
77
  if (nodeEnv !== "development" && nodeEnv !== "production") {
77
- throw new Error(`配置错误:NODE_ENV 只能是 'development' 或 'production',当前值=${String(nodeEnv)}`);
78
+ throw new CoreError({
79
+ message: `配置错误:NODE_ENV 只能是 'development' 或 'production',当前值=${String(nodeEnv)}`,
80
+ kind: "validation",
81
+ noLog: true,
82
+ meta: { subsystem: "config", operation: "loadBeflyConfig" }
83
+ });
78
84
  }
79
85
  // 使用 importDefault 加载 configs 目录下的配置文件。2222
80
86
  // 合并顺序:defaultOptions ← befly.common.json ← befly.development/production.json
@@ -92,16 +98,31 @@ export async function loadBeflyConfig(nodeEnv) {
92
98
  if (typeof redisPrefix === "string") {
93
99
  const trimmedPrefix = redisPrefix.trim();
94
100
  if (trimmedPrefix.includes(":")) {
95
- throw new Error(`配置错误:redis.prefix 不允许包含 ':'(RedisHelper 会自动拼接分隔符 ':'),请改为不带冒号的前缀,例如 'befly_demo',当前值=${redisPrefix}`);
101
+ throw new CoreError({
102
+ message: `配置错误:redis.prefix 不允许包含 ':'(RedisHelper 会自动拼接分隔符 ':'),请改为不带冒号的前缀,例如 'befly_demo',当前值=${redisPrefix}`,
103
+ kind: "validation",
104
+ noLog: true,
105
+ meta: { subsystem: "config", operation: "loadBeflyConfig" }
106
+ });
96
107
  }
97
108
  }
98
109
  const idMode = config.db?.idMode;
99
110
  if (idMode !== undefined && idMode !== "timeId" && idMode !== "autoId") {
100
- throw new Error(`配置错误:db.idMode 只能是 'timeId' 或 'autoId',当前值=${String(idMode)}`);
111
+ throw new CoreError({
112
+ message: `配置错误:db.idMode 只能是 'timeId' 或 'autoId',当前值=${String(idMode)}`,
113
+ kind: "validation",
114
+ noLog: true,
115
+ meta: { subsystem: "config", operation: "loadBeflyConfig" }
116
+ });
101
117
  }
102
118
  const strict = config.strict;
103
119
  if (strict !== undefined && typeof strict !== "boolean") {
104
- throw new Error(`配置错误:strict 必须为 boolean,当前值=${String(strict)}`);
120
+ throw new CoreError({
121
+ message: `配置错误:strict 必须为 boolean,当前值=${String(strict)}`,
122
+ kind: "validation",
123
+ noLog: true,
124
+ meta: { subsystem: "config", operation: "loadBeflyConfig" }
125
+ });
105
126
  }
106
127
  return config;
107
128
  }