class BingAdsRubySdk::Errors::ApplicationFault
Base exception class for handling errors where the detail is supplied
Public Class Methods
new(response)
click to toggle source
Calls superclass method
BingAdsRubySdk::Errors::GeneralError::new
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 38 def initialize(response) super populate_error_lists end
Private Class Methods
define_error_lists(*error_list_array)
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 111 def define_error_lists(*error_list_array) self.error_lists += error_list_array error_list_array.each { |attr| attr_accessor attr } end
error_lists()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 107 def error_lists @error_lists ||= [] end
error_lists=(value)
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 103 def error_lists=(value) @error_lists = value end
Public Instance Methods
message()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 44 def message error_list = all_errors return @message if error_list.empty? first_message = first_error_message(error_list) if error_list.count > 1 "API raised #{ error_list.count } errors, including: #{first_message}" else first_message end end
Private Instance Methods
all_errors()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 64 def all_errors self.class.error_lists.flat_map do |list_name| list = send(list_name) # Call sometimes returns an empty string instead of # nil for empty lists list.nil? || list.empty? ? nil : list end.compact end
array_wrap(value)
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 93 def array_wrap(value) case value when Array then value when nil, "" then [] else [value] end end
fault_hash()
click to toggle source
The fault hash from the API response detail element @return [Hash] containing the fault information if provided @return [Hash] empty hash if no fault information
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 77 def fault_hash raw_response[:detail][fault_key] || {} end
fault_key()
click to toggle source
The fault key that corresponds to the inherited class @return [Symbol] the fault key
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 83 def fault_key class_name = self.class.name.split('::').last BingAdsRubySdk::StringUtils.snakize(class_name).to_sym end
first_error_message(error_list)
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 88 def first_error_message(error_list) error = error_list.first.values.first format_message(error[:error_code], error[:message]) end
populate_error_lists()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/errors.rb, line 58 def populate_error_lists self.class.error_lists.each do |key| instance_variable_set("@#{key}", array_wrap(fault_hash[key])) end end