Skip to content

Commit 039919d

Browse files
committed
feat(browser): Allow mechanism to be provided as a hint.
- Provide 'angular' as the mechanism for handled angular errors.
1 parent ce67a38 commit 039919d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HttpErrorResponse } from '@angular/common/http';
22
import { ErrorHandler as AngularErrorHandler, Inject, Injectable } from '@angular/core';
33
import * as Sentry from '@sentry/browser';
4+
import { getCurrentHub } from '@sentry/browser';
45

56
import { runOutsideAngular } from './zone';
67

@@ -40,7 +41,9 @@ class SentryErrorHandler implements AngularErrorHandler {
4041
const extractedError = this._extractError(error) || 'Handled unknown error';
4142

4243
// Capture handled exception and send it to Sentry.
43-
const eventId = runOutsideAngular(() => Sentry.captureException(extractedError));
44+
const eventId = runOutsideAngular(() =>
45+
getCurrentHub().captureException(extractedError, { data: { mechanism: { type: 'angular', handled: false } } }),
46+
);
4447

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

packages/browser/src/eventbuilder.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { Event, EventHint, Exception, Severity, SeverityLevel, StackFrame, StackParser } from '@sentry/types';
1+
import {
2+
Event,
3+
EventHint,
4+
Exception,
5+
Mechanism,
6+
Severity,
7+
SeverityLevel,
8+
StackFrame,
9+
StackParser,
10+
} from '@sentry/types';
211
import {
312
addExceptionMechanism,
413
addExceptionTypeValue,
@@ -149,8 +158,17 @@ export function eventFromException(
149158
): PromiseLike<Event> {
150159
const syntheticException = (hint && hint.syntheticException) || undefined;
151160
const event = eventFromUnknownInput(stackParser, exception, syntheticException, attachStacktrace);
152-
addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
161+
const providedMechanism: Mechanism | undefined =
162+
hint && hint.data && (hint.data as { mechanism: Mechanism }).mechanism;
163+
const mechanism: Mechanism = providedMechanism || {
164+
handled: true,
165+
type: 'generic',
166+
};
167+
168+
addExceptionMechanism(event, mechanism);
169+
153170
event.level = 'error';
171+
154172
if (hint && hint.event_id) {
155173
event.event_id = hint.event_id;
156174
}

0 commit comments

Comments
 (0)