sobey-monitor-sdk 1.1.16 → 1.1.17
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 +28 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +28 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +28 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/types/index.d.ts +6 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -104,6 +104,12 @@ interface ErrorMonitorConfig {
|
|
|
104
104
|
* 任一规则匹配时将上报 http_error
|
|
105
105
|
*/
|
|
106
106
|
businessErrorRules?: BusinessErrorRule[];
|
|
107
|
+
/**
|
|
108
|
+
* 要监听的 HTTP 错误状态码列表
|
|
109
|
+
* 如果不配置或为空数组,则默认不捕获 HTTP 错误
|
|
110
|
+
* 例如: [404, 500, 502, 503, 504]
|
|
111
|
+
*/
|
|
112
|
+
httpErrorStatusCodes?: number[];
|
|
107
113
|
}
|
|
108
114
|
/**
|
|
109
115
|
* 性能监控配置
|
package/dist/index.esm.js
CHANGED
|
@@ -830,6 +830,30 @@ function isSdkRequest(url) {
|
|
|
830
830
|
}
|
|
831
831
|
return false;
|
|
832
832
|
}
|
|
833
|
+
/**
|
|
834
|
+
* 根据配置的状态码列表判断是否应该上报 HTTP 错误
|
|
835
|
+
* @param status HTTP 状态码
|
|
836
|
+
* @returns 是否应该上报
|
|
837
|
+
*/
|
|
838
|
+
function shouldReportHttpError(status) {
|
|
839
|
+
// 获取配置的状态码列表
|
|
840
|
+
if (!config.isInitialized()) {
|
|
841
|
+
// 配置未初始化时,不上报
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
const cfg = config.get();
|
|
845
|
+
const httpErrorStatusCodes = cfg.error?.httpErrorStatusCodes;
|
|
846
|
+
// 如果未配置状态码列表或为空数组,则不上报任何HTTP错误
|
|
847
|
+
if (!httpErrorStatusCodes || httpErrorStatusCodes.length === 0) {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
// 只检查状态码是否在配置的列表中
|
|
851
|
+
const shouldReport = httpErrorStatusCodes.includes(status);
|
|
852
|
+
if (cfg.debug) {
|
|
853
|
+
console.log(`[Monitor] HTTP status ${status} shouldReport: ${shouldReport}, configured codes:`, httpErrorStatusCodes);
|
|
854
|
+
}
|
|
855
|
+
return shouldReport;
|
|
856
|
+
}
|
|
833
857
|
/**
|
|
834
858
|
* 获取嵌套对象的字段值
|
|
835
859
|
* @param obj 对象
|
|
@@ -975,8 +999,8 @@ function interceptXHR() {
|
|
|
975
999
|
});
|
|
976
1000
|
}
|
|
977
1001
|
const responseBody = this.responseText?.substring(0, 1000);
|
|
978
|
-
// HTTP
|
|
979
|
-
if (status
|
|
1002
|
+
// HTTP 错误(根据配置的状态码列表过滤)
|
|
1003
|
+
if (shouldReportHttpError(status)) {
|
|
980
1004
|
reportHttpError({
|
|
981
1005
|
method: monitorData.method,
|
|
982
1006
|
url: monitorData.url,
|
|
@@ -1049,8 +1073,8 @@ function interceptFetch() {
|
|
|
1049
1073
|
responseBody = responseBody.substring(0, 1000);
|
|
1050
1074
|
}
|
|
1051
1075
|
catch { }
|
|
1052
|
-
if (!response.ok) {
|
|
1053
|
-
// HTTP
|
|
1076
|
+
if (!response.ok && shouldReportHttpError(status)) {
|
|
1077
|
+
// HTTP 错误(根据配置的状态码列表过滤)
|
|
1054
1078
|
reportHttpError({
|
|
1055
1079
|
method,
|
|
1056
1080
|
url,
|