lib/hubspot/discovery/base_api_client.rb in hubspot-api-client-14.3.0 vs lib/hubspot/discovery/base_api_client.rb in hubspot-api-client-14.4.0
- old
+ new
@@ -46,17 +46,28 @@
def codegen_module_name
codegen_api_class.gsub(/(.*)::.*/, '\1')
end
+ def call_api(api_method, params_to_pass)
+ api.public_send(api_method, *params_to_pass)
+ end
+
+ def call_api_with_rescue(api_method, params_to_pass)
+ error = Kernel.const_get("#{codegen_module_name}::ApiError")
+ call_api(api_method, params_to_pass)
+ rescue error => e
+ yield(e)
+ end
+
def define_methods
define_api_methods
end
def define_api_methods
api_methods.each do |api_method|
- self.class.define_method(api_method) do |params = {}|
+ self.class.define_method(api_method) do |params = {}, &block|
params_with_defaults = params
params_with_defaults[:opts] ||= {}
params_with_defaults[:opts][:auth_names] = if base_params[:access_token]
'oauth2'
elsif base_params[:api_key]
@@ -81,10 +92,11 @@
raise "Param #{param} is required for #{api.class}\##{api_method} method" if req == :req && params_with_defaults[param].nil?
params_with_defaults[param]
end
- api.public_send(api_method, *params_to_pass)
+ return call_api_with_rescue(api_method, params_to_pass, &block) unless block.nil?
+ call_api(api_method, params_to_pass)
end
end
end
end
end