@lark-apaas/nestjs-capability 0.1.5-alpha.0 → 0.1.5-alpha.2

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/index.cjs CHANGED
@@ -63,7 +63,9 @@ var ErrorCodes = {
63
63
  /** 参数验证失败 */
64
64
  PARAMS_VALIDATION_ERROR: "k_ec_cap_004",
65
65
  /** 执行失败 */
66
- EXECUTION_ERROR: "k_ec_cap_005"
66
+ EXECUTION_ERROR: "k_ec_cap_005",
67
+ /** 计费受限 */
68
+ RATE_LIMIT_EXCEEDED: "k_ec_cap_006"
67
69
  };
68
70
 
69
71
  // src/services/template-engine.service.ts
@@ -956,13 +958,31 @@ var CapabilityService = class _CapabilityService {
956
958
  });
957
959
  yield {
958
960
  type: "error",
959
- error: {
960
- code: "EXECUTION_ERROR",
961
- message: error instanceof Error ? error.message : String(error)
962
- }
961
+ error: this.extractErrorInfo(error)
963
962
  };
964
963
  }
965
964
  }
965
+ /**
966
+ * 从错误对象提取错误信息
967
+ * 支持 PluginError 和 RateLimitError
968
+ */
969
+ extractErrorInfo(error) {
970
+ const err = error;
971
+ const code = err?.code ?? "EXECUTION_ERROR";
972
+ const message = err instanceof Error ? err.message : String(err);
973
+ if (code === "RATE_LIMIT_EXCEEDED" && err?.rateLimitCode) {
974
+ return {
975
+ code,
976
+ message,
977
+ rateLimitCode: err.rateLimitCode,
978
+ rateLimitMessage: err.rateLimitMessage
979
+ };
980
+ }
981
+ return {
982
+ code,
983
+ message
984
+ };
985
+ }
966
986
  buildActionContext(pluginKey, override) {
967
987
  return {
968
988
  pluginKey,
@@ -1157,6 +1177,15 @@ var DebugController = class _DebugController {
1157
1177
  error_msg: `Action '${error.actionName}' not found in plugin ${error.pluginKey}`
1158
1178
  };
1159
1179
  }
1180
+ const err = error;
1181
+ if (err?.code === "RATE_LIMIT_EXCEEDED" && err?.rateLimitCode) {
1182
+ return {
1183
+ status_code: ErrorCodes.RATE_LIMIT_EXCEEDED,
1184
+ error_msg: err.rateLimitMessage || err.message,
1185
+ rate_limit_code: err.rateLimitCode,
1186
+ rate_limit_message: err.rateLimitMessage
1187
+ };
1188
+ }
1160
1189
  return {
1161
1190
  status_code: ErrorCodes.EXECUTION_ERROR,
1162
1191
  error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
@@ -1230,8 +1259,12 @@ var DebugController = class _DebugController {
1230
1259
  data: {
1231
1260
  type: "error",
1232
1261
  error: {
1233
- code: 0,
1234
- message: event.error.message
1262
+ code: event.error.code === "RATE_LIMIT_EXCEEDED" ? 429 : 0,
1263
+ message: event.error.message,
1264
+ ...event.error.rateLimitCode && {
1265
+ rateLimitCode: event.error.rateLimitCode,
1266
+ rateLimitMessage: event.error.rateLimitMessage
1267
+ }
1235
1268
  }
1236
1269
  }
1237
1270
  };
@@ -1258,14 +1291,20 @@ var DebugController = class _DebugController {
1258
1291
  }
1259
1292
  res.end();
1260
1293
  } catch (error) {
1294
+ const err = error;
1261
1295
  const errorMsg = error instanceof Error ? error.message : String(error);
1296
+ const isRateLimitError = err?.code === "RATE_LIMIT_EXCEEDED" && err?.rateLimitCode;
1262
1297
  const response = {
1263
1298
  status_code: ErrorCodes.SUCCESS,
1264
1299
  data: {
1265
1300
  type: "error",
1266
1301
  error: {
1267
- code: 0,
1268
- message: errorMsg
1302
+ code: isRateLimitError ? 429 : 0,
1303
+ message: errorMsg,
1304
+ ...isRateLimitError && {
1305
+ rateLimitCode: err.rateLimitCode,
1306
+ rateLimitMessage: err.rateLimitMessage
1307
+ }
1269
1308
  }
1270
1309
  }
1271
1310
  };
@@ -1409,6 +1448,15 @@ var WebhookController = class _WebhookController {
1409
1448
  error_msg: `Action '${error.actionName}' not found in plugin ${error.pluginKey}`
1410
1449
  };
1411
1450
  }
1451
+ const err = error;
1452
+ if (err?.code === "RATE_LIMIT_EXCEEDED" && err?.rateLimitCode) {
1453
+ return {
1454
+ status_code: ErrorCodes.RATE_LIMIT_EXCEEDED,
1455
+ error_msg: err.rateLimitMessage || err.message,
1456
+ rate_limit_code: err.rateLimitCode,
1457
+ rate_limit_message: err.rateLimitMessage
1458
+ };
1459
+ }
1412
1460
  return {
1413
1461
  status_code: ErrorCodes.EXECUTION_ERROR,
1414
1462
  error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
@@ -1476,8 +1524,12 @@ var WebhookController = class _WebhookController {
1476
1524
  data: {
1477
1525
  type: "error",
1478
1526
  error: {
1479
- code: 0,
1480
- message: event.error.message
1527
+ code: event.error.code === "RATE_LIMIT_EXCEEDED" ? 429 : 0,
1528
+ message: event.error.message,
1529
+ ...event.error.rateLimitCode && {
1530
+ rateLimitCode: event.error.rateLimitCode,
1531
+ rateLimitMessage: event.error.rateLimitMessage
1532
+ }
1481
1533
  }
1482
1534
  }
1483
1535
  };
@@ -1504,14 +1556,20 @@ var WebhookController = class _WebhookController {
1504
1556
  }
1505
1557
  res.end();
1506
1558
  } catch (error) {
1559
+ const err = error;
1507
1560
  const errorMsg = error instanceof Error ? error.message : String(error);
1561
+ const isRateLimitError = err?.code === "RATE_LIMIT_EXCEEDED" && err?.rateLimitCode;
1508
1562
  const response = {
1509
1563
  status_code: ErrorCodes.SUCCESS,
1510
1564
  data: {
1511
1565
  type: "error",
1512
1566
  error: {
1513
- code: 0,
1514
- message: errorMsg
1567
+ code: isRateLimitError ? 429 : 0,
1568
+ message: errorMsg,
1569
+ ...isRateLimitError && {
1570
+ rateLimitCode: err.rateLimitCode,
1571
+ rateLimitMessage: err.rateLimitMessage
1572
+ }
1515
1573
  }
1516
1574
  }
1517
1575
  };