module Google::Ads::GoogleAds::Errors

Constants

ERROR_CODES_MAPPING
ERROR_NAMESPACES
MEANINGLESS_PATHS
OPERATIONS

Public Class Methods

code(error, version = nil) click to toggle source

takes a Google::Ads::GoogleAds::VX::Errors::GoogleAdsError error and extracts error code in the form of a hash

Returns a Hash { name:, value:}

# File lib/google/ads/google_ads/errors.rb, line 84
def self.code(error, version = nil)
  error_version = error.class.name.split("::")[3]
  if error_version.nil?
    raise RuntimeError, "passed error is not a google ads class"
  end

  error_version = error_version.upcase.to_sym

  if version != nil
    Deprecation.new(false, false).deprecate(
      "Passing explicit versions to #code is deprecated, instead" \
      " we now infer it from the passed object."
    )
  end

  if version != nil && error_version.to_s != version.to_s
    raise ArgumentError,
      "passed version must match verison class of error"
  end

  version = error_version

  mapping = ERROR_CODES_MAPPING.fetch(version)
  match = mapping.find do |error_name|
    error.error_code.send(error_name) != :UNSPECIFIED
  end
  if match
    { name: match, value: error.error_code.send(match) }
  else
    {  }
  end
end
index(error) click to toggle source

takes a Google::Ads::GoogleAds::VX::Errors::GoogleAdsError error and extracts its index in the list of mutations

Return nil if not found Return Integer: index of the error

# File lib/google/ads/google_ads/errors.rb, line 51
def self.index(error)
  path = error.location.field_path_elements.find {|elt| elt.field_name == OPERATIONS }
  if path
    ret = path.index
    # TODO: Once v5 is sunset, we can always just return path.index.
    if ret.class == Integer
      ret
    else
      ret.value
    end
  else
    nil
  end
end
message(error) click to toggle source

takes a Google::Ads::GoogleAds::VX::Errors::GoogleAdsError error and extracts a full error message based on the message and the different paths describing the source of the error

Returns a string describing the error

# File lib/google/ads/google_ads/errors.rb, line 71
def self.message(error)
  error.location.field_path_elements.inject(error.message) do |string, path|
    unless MEANINGLESS_PATHS.include?(path.field_name)
      string = "#{path.field_name} - #{string}"
    end
    string
  end
end
namespaces() click to toggle source
# File lib/google/ads/google_ads/errors.rb, line 42
def self.namespaces
  ERROR_NAMESPACES.values
end