Sha256: b4efae4be4c9e30379f066c25d744f3331ed4d3221e5f39288feef62c2c71f1c

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

require "uri"
require "http"

module LaunchDarkly
  # @private
  module Util
    def self.stringify_attrs(hash, attrs)
      return hash if hash.nil?
      ret = hash
      changed = false
      attrs.each do |attr|
        value = hash[attr]
        if !value.nil? && !value.is_a?(String)
          ret = hash.clone if !changed
          ret[attr] = value.to_s
          changed = true
        end
      end
      ret
    end
    
    def self.new_http_client(uri_s, config)
      http_client_options = {}
      if config.socket_factory
        http_client_options["socket_class"] = config.socket_factory
      end
      return HTTP::Client.new(http_client_options)
        .timeout({
          read: config.read_timeout,
          connect: config.connect_timeout
        })
        .persistent(uri_s)
    end

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

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

    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
launchdarkly-server-sdk-6.2.5 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.2.4 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.2.3 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.2.2 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.2.1 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.2.0 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.1.1 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.1.0 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-6.0.0 lib/ldclient-rb/util.rb