This is an automated email from the ASF dual-hosted git repository. qiuxiafan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking-client-js.git
The following commit(s) were added to refs/heads/master by this push: new 5361fdc fix: the firstReportedError is calculated with more types of errors (#63) 5361fdc is described below commit 5361fdcd219a9cf3f62a95051eed1acdf78643b4 Author: Fine0830 <fine0...@outlook.com> AuthorDate: Wed Jul 7 11:07:43 2021 +0800 fix: the firstReportedError is calculated with more types of errors (#63) * fix: catch errors * fix: update error types for metrics --- src/services/base.ts | 7 ++++++- src/trace/interceptors/fetch.ts | 28 +++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/services/base.ts b/src/services/base.ts index 005a513..fccf016 100644 --- a/src/services/base.ts +++ b/src/services/base.ts @@ -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; } diff --git a/src/trace/interceptors/fetch.ts b/src/trace/interceptors/fetch.ts index baeb96b..d1467e3 100644 --- a/src/trace/interceptors/fetch.ts +++ b/src/trace/interceptors/fetch.ts @@ -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 = {