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