Skip to content

Commit

Permalink
fix: the firstReportedError is calculated with more types of errors (#63
Browse files Browse the repository at this point in the history
)

* fix: catch errors

* fix: update error types for metrics
  • Loading branch information
Fine0830 authored Jul 7, 2021
1 parent 39dd135 commit 5361fdc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/services/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ export default class Base {

public traceInfo(logInfo?: ErrorInfoFields & ReportFields & { collector: string }) {
this.logInfo = logInfo || this.logInfo;
const ExcludeErrorTypes: string[] = [
ErrorsCategory.AJAX_ERROR,
ErrorsCategory.RESOURCE_ERROR,
ErrorsCategory.UNKNOWN_ERROR,
];
// mark js error pv
if (!jsErrorPv && this.logInfo.category === ErrorsCategory.JS_ERROR) {
if (!jsErrorPv && !ExcludeErrorTypes.includes(this.logInfo.category)) {
jsErrorPv = true;
this.logInfo.firstReportedError = true;
}
Expand Down
28 changes: 15 additions & 13 deletions src/trace/interceptors/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,21 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen
.json()
.then((body: any) => body)
.catch((err: any) => err);
const logInfo = {
uniqueId: uuid(),
service: options.service,
serviceVersion: options.serviceVersion,
pagePath: options.pagePath,
category: ErrorsCategory.AJAX_ERROR,
grade: GradeTypeEnum.ERROR,
errorUrl: response.url || location.href,
message: `status: ${response.status}; statusText: ${response.statusText};`,
collector: options.collector,
stack: 'Fetch: ' + response.statusText,
};
new Base().traceInfo(logInfo);
if (response.status === 0 || response.status >= 400) {
const logInfo = {
uniqueId: uuid(),
service: options.service,
serviceVersion: options.serviceVersion,
pagePath: options.pagePath,
category: ErrorsCategory.AJAX_ERROR,
grade: GradeTypeEnum.ERROR,
errorUrl: response.url || location.href,
message: `status: ${response.status}; statusText: ${response.statusText};`,
collector: options.collector,
stack: 'Fetch: ' + response.statusText,
};
new Base().traceInfo(logInfo);
}
if (hasTrace) {
const endTime = new Date().getTime();
const exitSpan: SpanFields = {
Expand Down

0 comments on commit 5361fdc

Please sign in to comment.