class BingAdsRubySdk::Errors::ErrorHandler
Parses the response from the API to raise errors if they are returned
Constants
- BASE_FAULT
- ERRORS_MAPPING
- ERROR_KEYS
- PARTIAL_ERROR_KEYS
Attributes
response[R]
Public Class Methods
new(response)
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 7 def initialize(response) @response = response end
Public Instance Methods
call()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 11 def call # Some operations don't return a response, for example: # https://msdn.microsoft.com/en-us/library/bing-ads-customer-management-deleteaccount.aspx return unless response.is_a? Hash raise fault_class.new(response) if contains_error? end
Private Instance Methods
contains_error?()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 22 def contains_error? partial_error_keys.any? || contains_fault? end
contains_fault?()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 26 def contains_fault? (ERROR_KEYS & response.keys).any? end
fault_class()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 30 def fault_class ERRORS_MAPPING.fetch(hash_with_error.keys.first, BASE_FAULT) end
hash_with_error()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 34 def hash_with_error response[:detail] || partial_errors || {} end
partial_error_keys()
click to toggle source
Gets populated partial error keys from the response @return [Array] array of symbols for keys in the response
that are populated with errors
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 45 def partial_error_keys @partial_error_keys ||= (PARTIAL_ERROR_KEYS & response.keys).reject do |key| response[key].nil? || response[key].is_a?(String) end end
partial_errors()
click to toggle source
# File lib/bing_ads_ruby_sdk/errors/error_handler.rb, line 38 def partial_errors response.select {|key| partial_error_keys.include?(key)} end