Module: LaunchDarkly::Util
- Defined in:
- lib/ldclient-rb/util.rb
Class Method Summary collapse
- .http_error_message(status, context, recoverable_message) ⇒ Object
- .http_error_recoverable?(status) ⇒ Boolean
- .log_exception(logger, message, exc) ⇒ Object
- .new_http_client(uri_s, config) ⇒ Object
- .stringify_attrs(hash, attrs) ⇒ Object
Class Method Details
.http_error_message(status, context, recoverable_message) ⇒ Object
48 49 50 51 52 |
# File 'lib/ldclient-rb/util.rb', line 48 def self.(status, context, ) desc = (status == 401 || status == 403) ? " (invalid SDK key)" : "" = Util.http_error_recoverable?(status) ? : "giving up permanently" "HTTP error #{status}#{desc} for #{context} - #{}" end |
.http_error_recoverable?(status) ⇒ Boolean
40 41 42 43 44 45 46 |
# File 'lib/ldclient-rb/util.rb', line 40 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
35 36 37 38 |
# File 'lib/ldclient-rb/util.rb', line 35 def self.log_exception(logger, , exc) logger.error { "[LDClient] #{}: #{exc.inspect}" } logger.debug { "[LDClient] Exception trace: #{exc.backtrace}" } end |
.new_http_client(uri_s, config) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ldclient-rb/util.rb', line 22 def self.new_http_client(uri_s, config) = {} if config.socket_factory ["socket_class"] = config.socket_factory end return HTTP::Client.new() .timeout({ read: config.read_timeout, connect: config.connect_timeout }) .persistent(uri_s) end |
.stringify_attrs(hash, attrs) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ldclient-rb/util.rb', line 7 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 |