How to use the @sentry/utils.SentryError function in @sentry/utils

To help you get started, we’ve selected a few @sentry/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getsentry / sentry-javascript / packages / node / src / transports / base.ts View on Github external
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);
github getsentry / sentry-javascript / packages / core / src / dsn.ts View on Github external
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);
    }
  }
}
github getsentry / sentry-javascript / packages / node / src / transports / base.ts View on Github external
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 {
github getsentry / sentry-javascript / packages / browser / src / transports / base.ts View on Github external
public sendEvent(_: Event): PromiseLike {
    throw new SentryError('Transport Class has to implement `sendEvent` method');
  }
github getsentry / sentry-javascript / packages / node / src / transports / https.ts View on Github external
public sendEvent(event: Event): Promise {
    if (!this.module) {
      throw new SentryError('No module available in HTTPSTransport');
    }
    return this._sendWithModule(this.module, event);
  }
}
github getsentry / sentry-javascript / packages / node / src / transports / base.ts View on Github external
public sendEvent(_: Event): PromiseLike {
    throw new SentryError('Transport Class has to implement `sendEvent` method.');
  }
github getsentry / sentry-javascript / packages / core / src / basebackend.ts View on Github external
public eventFromException(_exception: any, _hint?: EventHint): PromiseLike {
    throw new SentryError('Backend has to implement `eventFromException` method');
  }
github getsentry / sentry-javascript / packages / core / src / dsn.ts View on Github external
['protocol', 'user', 'host', 'projectId'].forEach(component => {
      if (!this[component as keyof DsnComponents]) {
        throw new SentryError(ERROR_MESSAGE);
      }
    });
github getsentry / sentry-javascript / packages / core / src / basebackend.ts View on Github external
public eventFromMessage(_message: string, _level?: Severity, _hint?: EventHint): PromiseLike {
    throw new SentryError('Backend has to implement `eventFromMessage` method');
  }
github getsentry / sentry-javascript / packages / node / src / transports / http.ts View on Github external
public sendEvent(event: Event): Promise {
    if (!this.module) {
      throw new SentryError('No module available in HTTPTransport');
    }
    return this._sendWithModule(this.module, event);
  }
}