Skip to content

Commit 5361fdc

Browse files
authored
fix: the firstReportedError is calculated with more types of errors (#63)
* fix: catch errors * fix: update error types for metrics
1 parent 39dd135 commit 5361fdc

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/services/base.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ export default class Base {
3737

3838
public traceInfo(logInfo?: ErrorInfoFields & ReportFields & { collector: string }) {
3939
this.logInfo = logInfo || this.logInfo;
40+
const ExcludeErrorTypes: string[] = [
41+
ErrorsCategory.AJAX_ERROR,
42+
ErrorsCategory.RESOURCE_ERROR,
43+
ErrorsCategory.UNKNOWN_ERROR,
44+
];
4045
// mark js error pv
41-
if (!jsErrorPv && this.logInfo.category === ErrorsCategory.JS_ERROR) {
46+
if (!jsErrorPv && !ExcludeErrorTypes.includes(this.logInfo.category)) {
4247
jsErrorPv = true;
4348
this.logInfo.firstReportedError = true;
4449
}

src/trace/interceptors/fetch.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,21 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen
9898
.json()
9999
.then((body: any) => body)
100100
.catch((err: any) => err);
101-
const logInfo = {
102-
uniqueId: uuid(),
103-
service: options.service,
104-
serviceVersion: options.serviceVersion,
105-
pagePath: options.pagePath,
106-
category: ErrorsCategory.AJAX_ERROR,
107-
grade: GradeTypeEnum.ERROR,
108-
errorUrl: response.url || location.href,
109-
message: `status: ${response.status}; statusText: ${response.statusText};`,
110-
collector: options.collector,
111-
stack: 'Fetch: ' + response.statusText,
112-
};
113-
new Base().traceInfo(logInfo);
101+
if (response.status === 0 || response.status >= 400) {
102+
const logInfo = {
103+
uniqueId: uuid(),
104+
service: options.service,
105+
serviceVersion: options.serviceVersion,
106+
pagePath: options.pagePath,
107+
category: ErrorsCategory.AJAX_ERROR,
108+
grade: GradeTypeEnum.ERROR,
109+
errorUrl: response.url || location.href,
110+
message: `status: ${response.status}; statusText: ${response.statusText};`,
111+
collector: options.collector,
112+
stack: 'Fetch: ' + response.statusText,
113+
};
114+
new Base().traceInfo(logInfo);
115+
}
114116
if (hasTrace) {
115117
const endTime = new Date().getTime();
116118
const exitSpan: SpanFields = {

0 commit comments

Comments
 (0)