Skip to content

Commit 9c1efcd

Browse files
committed
set version in int() on global scope instead of captureException context
1 parent 4ce406a commit 9c1efcd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpErrorResponse } from '@angular/common/http';
2-
import { ErrorHandler as AngularErrorHandler, Inject, Injectable, VERSION } from '@angular/core';
2+
import { ErrorHandler as AngularErrorHandler, Inject, Injectable } from '@angular/core';
33
import * as Sentry from '@sentry/browser';
44

55
import { runOutsideAngular } from './zone';
@@ -39,10 +39,7 @@ class SentryErrorHandler implements AngularErrorHandler {
3939
const extractedError = this._extractError(error) || 'Handled unknown error';
4040

4141
// Capture handled exception and send it to Sentry.
42-
const angularVersion = VERSION && VERSION.major ? parseInt(VERSION.major, 10) : 0;
43-
const eventId = runOutsideAngular(() =>
44-
Sentry.captureException(extractedError, { contexts: { angular: { version: angularVersion } } }),
45-
);
42+
const eventId = runOutsideAngular(() => Sentry.captureException(extractedError));
4643

4744
// When in development mode, log the error to console for immediate feedback.
4845
if (this._options.logErrors) {

packages/angular/src/sdk.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { VERSION } from '@angular/core';
2-
import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser';
2+
import { BrowserOptions, init as browserInit, SDK_VERSION, setContext } from '@sentry/browser';
33
import { logger } from '@sentry/utils';
44

55
import { ANGULAR_MINIMUM_VERSION } from './constants';
@@ -20,20 +20,23 @@ export function init(options: BrowserOptions): void {
2020
],
2121
version: SDK_VERSION,
2222
};
23-
checkAngularVersion();
23+
24+
checkAndSetAngularVersion();
2425
browserInit(options);
2526
}
2627

27-
function checkAngularVersion(): void {
28-
if (VERSION && VERSION.major) {
29-
const major = parseInt(VERSION.major, 10);
30-
if (major < ANGULAR_MINIMUM_VERSION) {
28+
function checkAndSetAngularVersion(): void {
29+
const angularVersion = VERSION && VERSION.major ? parseInt(VERSION.major, 10) : undefined;
30+
31+
if (angularVersion) {
32+
if (angularVersion < ANGULAR_MINIMUM_VERSION) {
3133
IS_DEBUG_BUILD &&
3234
logger.warn(
33-
`The Sentry SDK does not officially support Angular ${major}.`,
35+
`The Sentry SDK does not officially support Angular ${angularVersion}.`,
3436
`This version of the Sentry SDK supports Angular ${ANGULAR_MINIMUM_VERSION} and above.`,
3537
'Please consider upgrading your Angular version or downgrading the Sentry SDK.',
3638
);
3739
}
40+
setContext('angular', { version: angularVersion });
3841
}
3942
}

0 commit comments

Comments
 (0)