code: def _build_error_report(
          self, message, report_location=None, http_context=None, user=None
      ):
          
          payload = {
              "serviceContext": {"service": self.service},
              "message": "{0}".format(message),
          }
  
          if self.version:
              payload["serviceContext"]["version"] = self.version
  
          if report_location or http_context or user:
              payload["context"] = {}
  
          if report_location:
              payload["context"]["reportLocation"] = report_location
  
          if http_context:
              http_context_dict = http_context.__dict__
              # strip out None values
              payload["context"]["httpRequest"] = {
                  key: value
                  for key, value in six.iteritems(http_context_dict)
                  if value is not None
              }
          if user:
              payload["context"]["user"] = user
          return payload
docs: Builds the Error Reporting object to report.
  
          This builds the object according to
  
          https://cloud.google.com/error-reporting/docs/formatting-error-messages
  
          :type message: str
          :param message: The stack trace that was reported or logged by the
                     service.
  
          :type report_location: dict
          :param report_location:  The location in the source code where the
                 decision was made to report the error, usually the place
                 where it was logged. For a logged exception this would be the
                 source line where the exception is logged, usually close to
                 the place where it was caught.
  
                 This should be a Python dict that contains the keys 'filePath',
                 'lineNumber', and 'functionName'
  
          :type http_context: :class`google.cloud.error_reporting.HTTPContext`
          :param http_context: The HTTP request which was processed when the
                               error was triggered.
  
          :type user: str
          :param user: The user who caused or was affected by the crash. This can
                       be a user ID, an email address, or an arbitrary token that
                       uniquely identifies the user. When sending an error
                       report, leave this field empty if the user was not
                       logged in. In this  case the Error Reporting system will
                       use other data, such as remote IP address,
                       to distinguish affected users.
          :rtype: dict
          :returns: A dict payload ready to be serialized to JSON and sent to
                    the API.