Skip to content

Commit d42ce46

Browse files
committed
re-use getPossibleEventMessages util
1 parent da5f630 commit d42ce46

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

packages/core/src/baseclient.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { SyncPromise, rejectedSyncPromise, resolvedSyncPromise } from './utils-h
5252
import { parseSampleRate } from './utils/parseSampleRate';
5353
import { prepareEvent } from './utils/prepareEvent';
5454
import { showSpanDropWarning } from './utils/spanUtils';
55+
import { getPossibleEventMessages } from './utils/eventUtils';
5556

5657
const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured.";
5758

@@ -714,13 +715,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
714715
*/
715716
protected _captureEvent(event: Event, hint: EventHint = {}, scope?: Scope): PromiseLike<string | undefined> {
716717
if (DEBUG_BUILD && isErrorEvent(event)) {
717-
logger.log(
718-
`Captured error event \`${
719-
(event.exception && event.exception.values && event.exception.values[0] && event.exception.values[0].value) ||
720-
event.message ||
721-
'<unknown>'
722-
}\``,
723-
);
718+
logger.log(`Captured error event \`${getPossibleEventMessages(event)[0] || '<unknown>'}\``);
724719
}
725720

726721
return this._processEvent(event, hint, scope).then(

packages/core/src/integrations/inboundfilters.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { defineIntegration } from '../integration';
55
import { logger } from '../utils-hoist/logger';
66
import { getEventDescription } from '../utils-hoist/misc';
77
import { stringMatchesSomePattern } from '../utils-hoist/string';
8+
import { getPossibleEventMessages } from '../utils/eventUtils';
89

910
// "Script error." is hard coded into browsers for errors that it can't read.
1011
// this is the result of a script being pulled in from an external domain and CORS.
@@ -117,7 +118,7 @@ function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): b
117118
return false;
118119
}
119120

120-
return _getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
121+
return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
121122
}
122123

123124
function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
@@ -147,32 +148,7 @@ function _isAllowedUrl(event: Event, allowUrls?: Array<string | RegExp>): boolea
147148
return !url ? true : stringMatchesSomePattern(url, allowUrls);
148149
}
149150

150-
function _getPossibleEventMessages(event: Event): string[] {
151-
const possibleMessages: string[] = [];
152151

153-
if (event.message) {
154-
possibleMessages.push(event.message);
155-
}
156-
157-
let lastException;
158-
try {
159-
// @ts-expect-error Try catching to save bundle size
160-
lastException = event.exception.values[event.exception.values.length - 1];
161-
} catch (e) {
162-
// try catching to save bundle size checking existence of variables
163-
}
164-
165-
if (lastException) {
166-
if (lastException.value) {
167-
possibleMessages.push(lastException.value);
168-
if (lastException.type) {
169-
possibleMessages.push(`${lastException.type}: ${lastException.value}`);
170-
}
171-
}
172-
}
173-
174-
return possibleMessages;
175-
}
176152

177153
function _isSentryError(event: Event): boolean {
178154
try {

packages/core/src/utils/eventUtils.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Event } from '../types-hoist';
2+
3+
/**
4+
* Get a list of possible event messages from a Sentry event.
5+
*/
6+
export function getPossibleEventMessages(event: Event): string[] {
7+
const possibleMessages: string[] = [];
8+
9+
if (event.message) {
10+
possibleMessages.push(event.message);
11+
}
12+
13+
let lastException;
14+
try {
15+
// @ts-expect-error Try catching to save bundle size
16+
lastException = event.exception.values[event.exception.values.length - 1];
17+
} catch (e) {
18+
// try catching to save bundle size checking existence of variables
19+
}
20+
21+
if (lastException) {
22+
if (lastException.value) {
23+
possibleMessages.push(lastException.value);
24+
if (lastException.type) {
25+
possibleMessages.push(`${lastException.type}: ${lastException.value}`);
26+
}
27+
}
28+
}
29+
30+
return possibleMessages;
31+
}

0 commit comments

Comments
 (0)