Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
res.on('data', () => {
// Drain
});
res.on('end', () => {
// Drain
});
});
req.on('error', reject);
private _validate(): void {
['protocol', 'user', 'host', 'projectId'].forEach(component => {
if (!this[component as keyof DsnComponents]) {
throw new SentryError(ERROR_MESSAGE);
}
});
if (this.protocol !== 'http' && this.protocol !== 'https') {
throw new SentryError(ERROR_MESSAGE);
}
if (this.port && isNaN(parseInt(this.port, 10))) {
throw new SentryError(ERROR_MESSAGE);
}
}
}
protected async _sendWithModule(httpModule: HTTPRequest, event: Event): Promise {
if (new Date(Date.now()) < this._disabledUntil) {
return Promise.reject(new SentryError(`Transport locked till ${this._disabledUntil} due to too many requests.`));
}
if (!this._buffer.isReady()) {
return Promise.reject(new SentryError('Not adding Promise due to buffer limit reached.'));
}
return this._buffer.add(
new Promise((resolve, reject) => {
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 {
public sendEvent(_: Event): PromiseLike {
throw new SentryError('Transport Class has to implement `sendEvent` method');
}
public sendEvent(event: Event): Promise {
if (!this.module) {
throw new SentryError('No module available in HTTPSTransport');
}
return this._sendWithModule(this.module, event);
}
}
public sendEvent(_: Event): PromiseLike {
throw new SentryError('Transport Class has to implement `sendEvent` method.');
}
public eventFromException(_exception: any, _hint?: EventHint): PromiseLike {
throw new SentryError('Backend has to implement `eventFromException` method');
}
['protocol', 'user', 'host', 'projectId'].forEach(component => {
if (!this[component as keyof DsnComponents]) {
throw new SentryError(ERROR_MESSAGE);
}
});
public eventFromMessage(_message: string, _level?: Severity, _hint?: EventHint): PromiseLike {
throw new SentryError('Backend has to implement `eventFromMessage` method');
}
public sendEvent(event: Event): Promise {
if (!this.module) {
throw new SentryError('No module available in HTTPTransport');
}
return this._sendWithModule(this.module, event);
}
}