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.cjs.js
CHANGED
|
@@ -834,6 +834,30 @@ 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
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
const cfg = config.get();
|
|
849
|
+
const httpErrorStatusCodes = cfg.error?.httpErrorStatusCodes;
|
|
850
|
+
// 如果未配置状态码列表或为空数组,则不上报任何HTTP错误
|
|
851
|
+
if (!httpErrorStatusCodes || httpErrorStatusCodes.length === 0) {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
// 只检查状态码是否在配置的列表中
|
|
855
|
+
const shouldReport = httpErrorStatusCodes.includes(status);
|
|
856
|
+
if (cfg.debug) {
|
|
857
|
+
console.log(`[Monitor] HTTP status ${status} shouldReport: ${shouldReport}, configured codes:`, httpErrorStatusCodes);
|
|
858
|
+
}
|
|
859
|
+
return shouldReport;
|
|
860
|
+
}
|
|
837
861
|
/**
|
|
838
862
|
* 获取嵌套对象的字段值
|
|
839
863
|
* @param obj 对象
|
|
@@ -979,8 +1003,8 @@ function interceptXHR() {
|
|
|
979
1003
|
});
|
|
980
1004
|
}
|
|
981
1005
|
const responseBody = this.responseText?.substring(0, 1000);
|
|
982
|
-
// HTTP
|
|
983
|
-
if (status
|
|
1006
|
+
// HTTP 错误(根据配置的状态码列表过滤)
|
|
1007
|
+
if (shouldReportHttpError(status)) {
|
|
984
1008
|
reportHttpError({
|
|
985
1009
|
method: monitorData.method,
|
|
986
1010
|
url: monitorData.url,
|
|
@@ -1053,8 +1077,8 @@ function interceptFetch() {
|
|
|
1053
1077
|
responseBody = responseBody.substring(0, 1000);
|
|
1054
1078
|
}
|
|
1055
1079
|
catch { }
|
|
1056
|
-
if (!response.ok) {
|
|
1057
|
-
// HTTP
|
|
1080
|
+
if (!response.ok && shouldReportHttpError(status)) {
|
|
1081
|
+
// HTTP 错误(根据配置的状态码列表过滤)
|
|
1058
1082
|
reportHttpError({
|
|
1059
1083
|
method,
|
|
1060
1084
|
url,
|