18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/zendesk_api/rescue.rb', line 18
def rescue_client_error(*args)
opts = args.last.is_a?(Hash) ? args.pop : {}
if args.any?
args.each do |method|
class_eval("alias :orig_#{method} :#{method}")
define_method method do |*args|
begin
send("orig_#{method}", *args)
rescue Faraday::Error::ClientError => e
log_error(e, method)
opts[:with].respond_to?(:call) ? opts[:with].call : opts[:with]
end
end
end
elsif block_given?
begin
yield
rescue Faraday::Error::ClientError => e
log_error(e)
opts[:with].respond_to?(:call) ? opts[:with].call : opts[:with]
end
end
end
|