Module: LoggedRequest

Included in:
RestClient::Request
Defined in:
lib/rest_client/core_ext/logged_request.rb

Instance Method Summary collapse

Instance Method Details

#logged_request(opts = {}, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rest_client/core_ext/logged_request.rb', line 2

def logged_request(opts = {}, &block)
  # We intend on using the following variables in this method's
  # ensure block. This means that we must take care to ensure
  # that we check for nil against these variables whenever they
  # are accessed.
  started = Time.now
  log_request(opts, started)
  response, exception = nil, nil
  response = execute(opts, &block)
rescue StandardError => ex
  exception = ex.class.to_s
  response = ex.respond_to?(:response) ? ex.response : nil
  raise ex # Re-raise the exception, we just wanted to capture it
ensure
  logged_response = opts.merge(exception: exception, response: response)
  ActiveSupport::Notifications.instrument(
    RestClient::Jogger.response_pattern,
    log_payload(logged_response, started)
  )
end