sobey-monitor-sdk 1.1.16 → 1.1.18

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
@@ -427,11 +427,11 @@ if (typeof window !== 'undefined') {
427
427
  });
428
428
  }
429
429
 
430
+ var version = "1.1.17";
431
+
430
432
  /**
431
433
  * 数据上报管理
432
434
  */
433
- // SDK 版本
434
- const SDK_VERSION$1 = '1.0.0';
435
435
  /**
436
436
  * 上报器类
437
437
  */
@@ -568,7 +568,7 @@ class Reporter {
568
568
  pageUrl: getPageUrl(),
569
569
  timestamp: Date.now(),
570
570
  userAgent: getUserAgent(),
571
- sdkVersion: cfg.version || SDK_VERSION$1,
571
+ sdkVersion: cfg.version || version,
572
572
  };
573
573
  }
574
574
  /**
@@ -834,6 +834,31 @@ function isSdkRequest(url) {
834
834
  }
835
835
  return false;
836
836
  }
837
+ /**
838
+ * 根据配置的状态码列表判断是否应该上报 HTTP 错误
839
+ * @param status HTTP 状态码
840
+ * @returns 是否应该上报
841
+ */
842
+ function shouldReportHttpError(status) {
843
+ // 获取配置的状态码列表
844
+ if (!config.isInitialized()) {
845
+ // 配置未初始化时,不上报
846
+ console.log(`[Monitor] shouldReportHttpError: config not initialized, status=${status}, returning false`);
847
+ return false;
848
+ }
849
+ const cfg = config.get();
850
+ const httpErrorStatusCodes = cfg.error?.httpErrorStatusCodes;
851
+ // 如果未配置状态码列表或为空数组,则不上报任何HTTP错误
852
+ if (!httpErrorStatusCodes || httpErrorStatusCodes.length === 0) {
853
+ console.log(`[Monitor] shouldReportHttpError: no httpErrorStatusCodes configured, status=${status}, returning false`);
854
+ return false;
855
+ }
856
+ // 只检查状态码是否在配置的列表中
857
+ const shouldReport = httpErrorStatusCodes.includes(status);
858
+ // 临时强制输出调试日志
859
+ console.log(`[Monitor] HTTP status ${status} shouldReport: ${shouldReport}, configured codes:`, httpErrorStatusCodes);
860
+ return shouldReport;
861
+ }
837
862
  /**
838
863
  * 获取嵌套对象的字段值
839
864
  * @param obj 对象
@@ -979,8 +1004,8 @@ function interceptXHR() {
979
1004
  });
980
1005
  }
981
1006
  const responseBody = this.responseText?.substring(0, 1000);
982
- // HTTP 错误或业务错误
983
- if (status === 0 || status >= 400) {
1007
+ // HTTP 错误(根据配置的状态码列表过滤)
1008
+ if (shouldReportHttpError(status)) {
984
1009
  reportHttpError({
985
1010
  method: monitorData.method,
986
1011
  url: monitorData.url,
@@ -1053,8 +1078,8 @@ function interceptFetch() {
1053
1078
  responseBody = responseBody.substring(0, 1000);
1054
1079
  }
1055
1080
  catch { }
1056
- if (!response.ok) {
1057
- // HTTP 错误
1081
+ if (!response.ok && shouldReportHttpError(status)) {
1082
+ // HTTP 错误(根据配置的状态码列表过滤)
1058
1083
  reportHttpError({
1059
1084
  method,
1060
1085
  url,
@@ -1097,13 +1122,16 @@ function interceptFetch() {
1097
1122
  },
1098
1123
  });
1099
1124
  }
1100
- reportHttpError({
1101
- method,
1102
- url,
1103
- status: 0,
1104
- duration,
1105
- requestBody,
1106
- });
1125
+ // 网络错误也遵守 httpErrorStatusCodes 配置
1126
+ if (shouldReportHttpError(0)) {
1127
+ reportHttpError({
1128
+ method,
1129
+ url,
1130
+ status: 0,
1131
+ duration,
1132
+ requestBody,
1133
+ });
1134
+ }
1107
1135
  throw error;
1108
1136
  }
1109
1137
  };
@@ -1914,8 +1942,6 @@ function createUseMonitorError(React) {
1914
1942
  * 前端监控 SDK
1915
1943
  * @description 错误监控、性能监控、行为监控
1916
1944
  */
1917
- // SDK 版本
1918
- const SDK_VERSION = '1.0.0';
1919
1945
  /**
1920
1946
  * 监控 SDK 主类
1921
1947
  */
@@ -1993,7 +2019,7 @@ class MonitorSDK {
1993
2019
  // 初始化配置管理器
1994
2020
  config.init({
1995
2021
  ...finalConfig,
1996
- version: finalConfig.version || SDK_VERSION,
2022
+ version: finalConfig.version || version,
1997
2023
  }, true);
1998
2024
  this.ready = true;
1999
2025
  this.loading = false;
@@ -2170,7 +2196,7 @@ class MonitorSDK {
2170
2196
  * 获取 SDK 版本
2171
2197
  */
2172
2198
  getVersion() {
2173
- return SDK_VERSION;
2199
+ return version;
2174
2200
  }
2175
2201
  }
2176
2202
  // 导出单例