Skip to content

Commit 3b51e30

Browse files
committed
browser: Fixed event creation based on the type
1 parent e6e0d2b commit 3b51e30

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/browser/src/backend.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Backend, logger, Options, SentryError } from '@sentry/core';
22
import { SentryEvent, SentryResponse, Status } from '@sentry/types';
33
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
44
import { supportsFetch } from '@sentry/utils/supports';
5-
import { eventFromStacktrace, getEventOptionsFromPlainObject, prepareFramesForEvent } from './parsers';
5+
import { eventFromPlainObject, eventFromStacktrace, prepareFramesForEvent } from './parsers';
66
import { computeStackTrace } from './tracekit';
77
import { FetchTransport, XHRTransport } from './transports';
88

@@ -58,10 +58,13 @@ export class BrowserBackend implements Backend {
5858
* @inheritDoc
5959
*/
6060
public async eventFromException(exception: any, syntheticException: Error | null): Promise<SentryEvent> {
61+
let event;
62+
6163
if (isErrorEvent(exception as ErrorEvent) && (exception as ErrorEvent).error) {
6264
// If it is an ErrorEvent with `error` property, extract it to get actual Error
6365
const ex = exception as ErrorEvent;
6466
exception = ex.error; // tslint:disable-line:no-parameter-reassignment
67+
event = eventFromStacktrace(computeStackTrace(exception as Error));
6568
} else if (isDOMError(exception as DOMError) || isDOMException(exception as DOMException)) {
6669
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
6770
// then we just extract the name and message, as they don't provide anything else
@@ -71,16 +74,16 @@ export class BrowserBackend implements Backend {
7174
const name = ex.name || (isDOMError(ex) ? 'DOMError' : 'DOMException');
7275
const message = ex.message ? `${name}: ${ex.message}` : name;
7376

74-
return this.eventFromMessage(message, syntheticException);
77+
event = await this.eventFromMessage(message, syntheticException);
7578
} else if (isError(exception as Error)) {
7679
// we have a real Error object, do nothing
80+
event = eventFromStacktrace(computeStackTrace(exception as Error));
7781
} else if (isPlainObject(exception as {})) {
7882
// If it is plain Object, serialize it manually and extract options
7983
// This will allow us to group events based on top-level keys
8084
// which is much better than creating new group when any key/value change
8185
const ex = exception as {};
82-
const options = getEventOptionsFromPlainObject(ex);
83-
exception = new Error(options.message); // tslint:disable-line:no-parameter-reassignment
86+
event = eventFromPlainObject(ex, syntheticException);
8487
} else {
8588
// If none of previous checks were valid, then it means that
8689
// it's not a DOMError/DOMException
@@ -89,11 +92,9 @@ export class BrowserBackend implements Backend {
8992
// it's not an Error
9093
// So bail out and capture it as a simple message:
9194
const ex = exception as string;
92-
return this.eventFromMessage(ex, syntheticException);
95+
event = await this.eventFromMessage(ex, syntheticException);
9396
}
9497

95-
let event: SentryEvent = eventFromStacktrace(computeStackTrace(exception as Error));
96-
9798
event = {
9899
...event,
99100
exception: {

0 commit comments

Comments
 (0)