Skip to content

Commit c3c2afa

Browse files
authored
* fix: getsentry#1949 * fix: Typo * fix: Lint * fix: Only in case of an error * fix: CR
1 parent 9a49307 commit c3c2afa

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- [browser] fix: GlobalHandler integration sometimes receives Event objects as message: Fix #1949
6+
37
## 5.1.2
48

59
- [browser] fix: Fixed a bug if Sentry was initialized multiple times: Fix #2043

packages/browser/src/integrations/globalhandlers.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import { Event, Integration } from '@sentry/types';
3-
import { addExceptionTypeValue, logger, normalize, truncate } from '@sentry/utils';
3+
import { addExceptionTypeValue, isString, logger, normalize, truncate } from '@sentry/utils';
44

55
import { eventFromStacktrace } from '../parsers';
66
import {
@@ -91,6 +91,14 @@ export class GlobalHandlers implements Integration {
9191
* @param stacktrace TraceKitStackTrace to be converted to an Event.
9292
*/
9393
private _eventFromGlobalHandler(stacktrace: TraceKitStackTrace): Event {
94+
if (!isString(stacktrace.message) && stacktrace.mechanism !== 'onunhandledrejection') {
95+
// There are cases where stacktrace.message is an Event object
96+
// https://github.com/getsentry/sentry-javascript/issues/1949
97+
// In this specific case we try to extract stacktrace.message.error.message
98+
const message = (stacktrace.message as unknown) as any;
99+
stacktrace.message =
100+
message.error && isString(message.error.message) ? message.error.message : 'No error message';
101+
}
94102
const event = eventFromStacktrace(stacktrace);
95103

96104
const data: { [key: string]: string } = {

0 commit comments

Comments
 (0)