Class: LHC::Rollbar

Inherits:
Interceptor show all
Includes:
ActiveSupport::Configurable, FixInvalidEncodingConcern
Defined in:
lib/lhc/interceptors/rollbar.rb

Instance Attribute Summary

Attributes inherited from Interceptor

#request

Instance Method Summary collapse

Methods inherited from Interceptor

#after_request, #all_interceptor_classes, #before_raw_request, #before_request, #before_response, dup, #initialize, #response

Constructor Details

This class inherits a constructor from LHC::Interceptor

Instance Method Details

#after_responseObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lhc/interceptors/rollbar.rb', line 9

def after_response
  return unless Object.const_defined?('Rollbar')
  return if response.success?

  request = response.request
  additional_params = request.options.fetch(:rollbar, {})
  data = {
    response: {
      body: response.body,
      code: response.code,
      headers: response.headers,
      time: response.time,
      timeout?: response.timeout?
    },
    request: {
      url: request.url,
      method: request.method,
      headers: request.scrubbed_headers,
      params: request.scrubbed_params
    }
  }.merge additional_params
  begin
    Rollbar.warning("Status: #{response.code} URL: #{request.url}", data)
  rescue Encoding::UndefinedConversionError
    sanitized_data = data.deep_transform_values { |value| self.class.fix_invalid_encoding(value) }
    Rollbar.warning("Status: #{response.code} URL: #{request.url}", sanitized_data)
  end
end