class LHC::Rollbar

def after_response

def after_response
  return unless Object.const_defined?(:Rollbar)
  return unless report?
  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 JSON::GeneratorError, 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