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