Class: CC::Service::Invocation::WithErrorHandling

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/service/invocation/with_error_handling.rb

Instance Method Summary collapse

Constructor Details

#initialize(invocation, logger, prefix = nil) ⇒ WithErrorHandling

Returns a new instance of WithErrorHandling.



3
4
5
6
7
# File 'lib/cc/service/invocation/with_error_handling.rb', line 3

def initialize(invocation, logger, prefix = nil)
  @invocation = invocation
  @logger = logger
  @prefix = prefix
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cc/service/invocation/with_error_handling.rb', line 9

def call
  @invocation.call
rescue CC::Service::HTTPError => e
  @logger.error(error_message(e))
  {
    ok: false,
    params: e.params,
    status: e.status,
    endpoint_url: e.endpoint_url,
    message: e.user_message || e.message,
    log_message: error_message(e),
  }
rescue => e
  @logger.error(error_message(e))
  {
    ok: false,
    message: e.message,
    log_message: error_message(e),
  }
end