Skip to content

Commit 91b73c8

Browse files
authored
feat(browser): Allow mechanism to be provided as a hint.
- Provide 'angular' as the mechanism for handled angular errors.
1 parent caae939 commit 91b73c8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
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, 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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Event, EventHint, Options, Severity } from '@sentry/types';
1+
import { Event, EventHint, Mechanism, Options, Severity } from '@sentry/types';
22
import {
33
addExceptionMechanism,
44
addExceptionTypeValue,
@@ -23,10 +23,15 @@ export function eventFromException(options: Options, exception: unknown, hint?:
2323
const event = eventFromUnknownInput(exception, syntheticException, {
2424
attachStacktrace: options.attachStacktrace,
2525
});
26-
addExceptionMechanism(event, {
26+
const providedMechanism: Mechanism | undefined =
27+
hint && hint.data && (hint.data as { mechanism: Mechanism }).mechanism;
28+
const mechanism: Mechanism = providedMechanism || {
2729
handled: true,
2830
type: 'generic',
29-
});
31+
};
32+
33+
addExceptionMechanism(event, mechanism);
34+
3035
event.level = Severity.Error;
3136
if (hint && hint.event_id) {
3237
event.event_id = hint.event_id;

0 commit comments

Comments
 (0)