sobey-monitor-sdk 1.1.9 → 1.1.10

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.js CHANGED
@@ -768,12 +768,20 @@ function installHttpErrorHandler() {
768
768
  * 检查是否是 SDK 自身的请求
769
769
  */
770
770
  function isSdkRequest(url) {
771
- if (!config.isInitialized())
772
- return false;
773
- const cfg = config.get();
774
- if (!cfg.dsn)
775
- return false;
776
- return url.includes(cfg.dsn);
771
+ // 检查是否匹配常见的 SDK 上报路径
772
+ if (url.includes('/monitor/api/report') ||
773
+ url.includes('/monitor/api/beacon') ||
774
+ url.includes('/monitor/api/config')) {
775
+ return true;
776
+ }
777
+ // 配置已初始化时,检查 dsn
778
+ if (config.isInitialized()) {
779
+ const cfg = config.get();
780
+ if (cfg.dsn && url.includes(cfg.dsn)) {
781
+ return true;
782
+ }
783
+ }
784
+ return false;
777
785
  }
778
786
  /**
779
787
  * 获取嵌套对象的字段值
@@ -963,35 +971,39 @@ function interceptFetch() {
963
971
  },
964
972
  });
965
973
  }
966
- // 克隆响应以读取 body(无论成功与否都需要,用于业务错误检测)
967
- const cloned = response.clone();
968
- let responseBody;
969
- try {
970
- responseBody = await cloned.text();
971
- responseBody = responseBody.substring(0, 1000);
972
- }
973
- catch { }
974
- if (!response.ok) {
975
- // HTTP 错误
976
- reportHttpError({
977
- method,
978
- url,
979
- status,
980
- duration,
981
- requestBody,
982
- responseBody,
983
- });
984
- }
985
- else if (detectBusinessError(responseBody)) {
986
- // HTTP 200 但检测到业务错误
987
- reportHttpError({
988
- method,
989
- url,
990
- status,
991
- duration,
992
- requestBody,
993
- responseBody,
994
- }, true);
974
+ // 检查是否配置了业务错误规则
975
+ const hasBusinessRules = cfg?.error?.businessErrorRules && cfg.error.businessErrorRules.length > 0;
976
+ // 只有在请求失败或配置了业务规则时才读取响应体
977
+ if (!response.ok || hasBusinessRules) {
978
+ const cloned = response.clone();
979
+ let responseBody;
980
+ try {
981
+ responseBody = await cloned.text();
982
+ responseBody = responseBody.substring(0, 1000);
983
+ }
984
+ catch { }
985
+ if (!response.ok) {
986
+ // HTTP 错误
987
+ reportHttpError({
988
+ method,
989
+ url,
990
+ status,
991
+ duration,
992
+ requestBody,
993
+ responseBody,
994
+ });
995
+ }
996
+ else if (hasBusinessRules && detectBusinessError(responseBody)) {
997
+ // HTTP 200 但检测到业务错误
998
+ reportHttpError({
999
+ method,
1000
+ url,
1001
+ status,
1002
+ duration,
1003
+ requestBody,
1004
+ responseBody,
1005
+ }, true);
1006
+ }
995
1007
  }
996
1008
  return response;
997
1009
  }