Module: LaunchDarkly::Util

Defined in:
lib/ldclient-rb/util.rb

Class Method Summary collapse

Class Method Details

.http_error_message(status, context, recoverable_message) ⇒ Object



42
43
44
45
46
# File 'lib/ldclient-rb/util.rb', line 42

def self.http_error_message(status, context, recoverable_message)
  desc = (status == 401 || status == 403) ? " (invalid SDK key)" : ""
  message = Util.http_error_recoverable?(status) ? recoverable_message : "giving up permanently"
  "HTTP error #{status}#{desc} for #{context} - #{message}"
end

.http_error_recoverable?(status) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/ldclient-rb/util.rb', line 34

def self.http_error_recoverable?(status)
  if status >= 400 && status < 500
    status == 400 || status == 408 || status == 429
  else
    true
  end
end

.log_exception(logger, message, exc) ⇒ Object



29
30
31
32
# File 'lib/ldclient-rb/util.rb', line 29

def self.log_exception(logger, message, exc)
  logger.error { "[LDClient] #{message}: #{exc.inspect}" }
  logger.debug { "[LDClient] Exception trace: #{exc.backtrace}" }
end

.new_http_client(uri_s, config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ldclient-rb/util.rb', line 7

def self.new_http_client(uri_s, config)
  http_client_options = {}
  if config.socket_factory
    http_client_options["socket_class"] = config.socket_factory
  end
  proxy = URI.parse(uri_s).find_proxy
  unless proxy.nil?
    http_client_options["proxy"] = {
      proxy_address: proxy.host,
      proxy_port: proxy.port,
      proxy_username: proxy.user,
      proxy_password: proxy.password,
    }
  end
  HTTP::Client.new(http_client_options)
    .timeout({
      read: config.read_timeout,
      connect: config.connect_timeout,
    })
    .persistent(uri_s)
end