StackdriverErrorReporter.prototype.report = function()

in stackdriver-errors.js [100:142]


StackdriverErrorReporter.prototype.report = function(err, options) {
  if (this.disabled) {
    return Promise.resolve(null);
  }
  if (!err) {
    return Promise.reject(new Error('no error to report'));
  }
  options = options || {};

  var payload = {};
  payload.serviceContext = this.serviceContext;
  payload.context = this.context;
  payload.context.httpRequest = {
    userAgent: window.navigator.userAgent,
    url: window.location.href,
  };

  var firstFrameIndex = 0;
  if (typeof err == 'string' || err instanceof String) {
    // Transform the message in an error, use try/catch to make sure the stacktrace is populated.
    try {
      throw new Error(err);
    } catch (e) {
      err = e;
    }
    // the first frame when using report() is always this library
    firstFrameIndex = options.skipLocalFrames || 1;
  }

  var reportUrl = this.targetUrl || (
    baseAPIUrl + this.projectId + '/events:report?key=' + this.apiKey);

  var customFunc = this.customReportingFunction;

  return resolveError(err, firstFrameIndex)
    .then(function(message) {
      payload.message = message;
      if (customFunc) {
        return customFunc(payload);
      }
      return sendErrorPayload(reportUrl, payload);
    });
};