Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function consoleBreadcrumb(handlerData: { [key: string]: any }): void {
const breadcrumb = {
category: 'console',
data: {
extra: {
arguments: normalize(handlerData.args, 3),
},
logger: 'console',
},
level: Severity.fromString(handlerData.level),
message: safeJoin(handlerData.args, ' '),
};
if (handlerData.level === 'assert') {
if (handlerData.args[0] === false) {
breadcrumb.message = `Assertion failed: ${safeJoin(handlerData.args.slice(1), ' ') || 'console.assert'}`;
breadcrumb.data.extra.arguments = normalize(handlerData.args.slice(1), 3);
} else {
// Don't capture a breadcrumb for passed assertions
return;
}
}
getCurrentHub().addBreadcrumb(breadcrumb, {
input: handlerData.args,
level: handlerData.level,
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');
}
}
const req = httpModule.request(this._getRequestOptions(), (res: http.IncomingMessage) => {
const statusCode = res.statusCode || 500;
const status = Status.fromHttpCode(statusCode);
res.setEncoding('utf8');
if (status === Status.Success) {
resolve({ status });
} else {
if (status === Status.RateLimit) {
const now = Date.now();
let header = res.headers ? res.headers['Retry-After'] : '';
header = Array.isArray(header) ? header[0] : header;
this._disabledUntil = new Date(now + parseRetryAfterHeader(now, header));
logger.warn(`Too many requests, backing off till: ${this._disabledUntil}`);
}
let rejectionMessage = `HTTP Error (${statusCode})`;
if (res.headers && res.headers['x-sentry-error']) {
rejectionMessage += `: ${res.headers['x-sentry-error']}`;
}
reject(new SentryError(rejectionMessage));
}
// Force the socket to drain
it(`/GET level`, async () => {
await request(app.getHttpServer())
.get('/level')
.expect(500);
expect(client.captureException.mock.calls[0][0]).toBeInstanceOf(Error);
expect(client.captureException.mock.calls[0][2]._level).toEqual(Sentry.Severity.Critical);
});
}))
extra() {
throw new Error('Something bad happened');
}
@Get('fingerprint')
@UseInterceptors(new RavenInterceptor({
fingerprint: ['A', 'B'],
}))
fingerprint() {
throw new Error('Something bad happened');
}
@Get('level')
@UseInterceptors(new RavenInterceptor({
level: Sentry.Severity.Critical,
}))
level() {
throw new Error('Something bad happened');
}
}
hub.withScope(scope => {
scope.setLevel(Severity.fromString(level));
scope.setExtra('arguments', normalize(args, 3));
scope.addEventProcessor(event => {
event.logger = 'console';
return event;
});
let message = safeJoin(args, ' ');
if (level === 'assert') {
if (args[0] === false) {
message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`;
scope.setExtra('arguments', normalize(args.slice(1), 3));
hub.captureMessage(message);
}
} else {
hub.captureMessage(message);
}
this.client.withScope((scope:Scope) => {
this.setupContext(scope);
this.client.captureMessage(msg, Severity.fromString(severity));
});
}
if (!hasIntegration || shouldIgnoreOnError() || isFailedOwnDelivery) {
if (self._oldOnUnhandledRejectionHandler) {
return self._oldOnUnhandledRejectionHandler.apply(this, arguments);
}
return true;
}
const client = currentHub.getClient();
const event = isPrimitive(error)
? self._eventFromIncompleteRejection(error)
: eventFromUnknownInput(error, undefined, {
attachStacktrace: client && client.getOptions().attachStacktrace,
rejection: true,
});
event.level = Severity.Error;
addExceptionMechanism(event, {
handled: false,
type: 'onunhandledrejection',
});
currentHub.captureEvent(event, {
originalException: error,
});
if (self._oldOnUnhandledRejectionHandler) {
return self._oldOnUnhandledRejectionHandler.apply(this, arguments);
}
return true;
};
public eventFromException(exception: any, hint?: EventHint): PromiseLike {
const syntheticException = (hint && hint.syntheticException) || undefined;
const event = eventFromUnknownInput(exception, syntheticException, {
attachStacktrace: this._options.attachStacktrace,
});
addExceptionMechanism(event, {
handled: true,
type: 'generic',
});
event.level = Severity.Error;
if (hint && hint.event_id) {
event.event_id = hint.event_id;
}
return SyncPromise.resolve(event);
}
/**
handlerData.fetchData.url.indexOf(filterUrl) !== -1 &&
handlerData.fetchData.method === 'POST' &&
handlerData.args[1] &&
handlerData.args[1].body
) {
addSentryBreadcrumb(handlerData.args[1].body);
return;
}
}
if (handlerData.error) {
getCurrentHub().addBreadcrumb(
{
category: 'fetch',
data: handlerData.fetchData,
level: Severity.Error,
type: 'http',
},
{
data: handlerData.error,
input: handlerData.args,
},
);
} else {
getCurrentHub().addBreadcrumb(
{
category: 'fetch',
data: handlerData.fetchData,
type: 'http',
},
{
input: handlerData.args,