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