Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _getEventFilterUrl(event: Event): string | null {
try {
if (event.stacktrace) {
// tslint:disable:no-unsafe-any
const frames = (event as any).stacktrace.frames;
return frames[frames.length - 1].filename;
}
if (event.exception) {
// tslint:disable:no-unsafe-any
const frames = (event as any).exception.values[0].stacktrace.frames;
return frames[frames.length - 1].filename;
}
return null;
} catch (oO) {
logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
return null;
}
}
}
private _getPossibleEventMessages(event: Event): string[] {
if (event.message) {
return [event.message];
}
if (event.exception) {
try {
// tslint:disable-next-line:no-unsafe-any
const { type, value } = (event as any).exception.values[0];
return [`${value}`, `${type}: ${value}`];
} catch (oO) {
logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
return [];
}
}
return [];
}
function addSentryBreadcrumb(serializedData: string): void {
// There's always something that can go wrong with deserialization...
try {
const event = JSON.parse(serializedData);
getCurrentHub().addBreadcrumb(
{
category: 'sentry',
event_id: event.event_id,
level: event.level || Severity.fromString('error'),
message: getEventDescription(event),
},
{
event,
},
);
} catch (_oO) {
logger.error('Error while adding sentry type breadcrumb');
}
}
private _getEventFilterUrl(event: Event): string | null {
try {
if (event.stacktrace) {
const frames = event.stacktrace.frames;
return (frames && frames[frames.length - 1].filename) || null;
}
if (event.exception) {
const frames =
event.exception.values && event.exception.values[0].stacktrace && event.exception.values[0].stacktrace.frames;
return (frames && frames[frames.length - 1].filename) || null;
}
return null;
} catch (oO) {
logger.error(`Cannot extract url for event ${getEventDescription(event)}`);
return null;
}
}
}
private _getPossibleEventMessages(event: Event): string[] {
if (event.message) {
return [event.message];
}
if (event.exception) {
try {
const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {};
return [`${value}`, `${type}: ${value}`];
} catch (oO) {
logger.error(`Cannot extract message for event ${getEventDescription(event)}`);
return [];
}
}
return [];
}
private _shouldDropEvent(event: Event, options: InboundFiltersOptions): boolean {
if (this._isSentryError(event, options)) {
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
}
if (this._isIgnoredError(event, options)) {
logger.warn(
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
);
return true;
}
if (this._isBlacklistedUrl(event, options)) {
logger.warn(
`Event dropped due to being matched by \`blacklistUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
return true;
}
if (!this._isWhitelistedUrl(event, options)) {
logger.warn(
`Event dropped due to not being matched by \`whitelistUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
return true;
}
return false;
}