Skip to content

Commit

Permalink
timeout exception logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-cat committed Apr 7, 2022
1 parent adaf386 commit 765622e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/configcat/autopollingcachepolicy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def force_refresh()
if !@_initialized && !old_configuration.equal?(nil)
@_initialized = true
end
rescue Timeout::Error => e
ConfigCat.logger.error("Request timed out. Timeout values: [open: %ss, read: %ss]" %
[@_config_fetcher.get_open_timeout(), @_config_fetcher.get_read_timeout()])
rescue Exception => e
ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
Expand Down
8 changes: 8 additions & 0 deletions lib/configcat/configfetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def initialize(sdk_key, mode, base_url:nil, proxy_address:nil, proxy_port:nil, p
end
end

def get_open_timeout()
return @_open_timeout
end

def get_read_timeout()
return @_read_timeout
end

# Returns the FetchResponse object contains configuration json Dictionary
def get_configuration_json(retries=0)
ConfigCat.logger.debug "Fetching configuration from ConfigCat"
Expand Down
8 changes: 8 additions & 0 deletions spec/configcat/autopollingcachepolicy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
expect(config).to eq TEST_JSON
cache_policy.stop()
end

it "test_init_wait_time_ok" do
config_fetcher = ConfigFetcherWaitMock.new(0)
config_cache = InMemoryConfigCache.new()
Expand All @@ -23,6 +24,7 @@
expect(config).to eq TEST_JSON
cache_policy.stop()
end

it "test_init_wait_time_timeout" do
config_fetcher = ConfigFetcherWaitMock.new(5)
config_cache = InMemoryConfigCache.new()
Expand All @@ -36,6 +38,7 @@
expect(elapsed_time).to be < 2
cache_policy.stop()
end

it "test_fetch_call_count" do
config_fetcher = ConfigFetcherMock.new()
config_cache = InMemoryConfigCache.new()
Expand All @@ -46,6 +49,7 @@
expect(config).to eq TEST_JSON
cache_policy.stop()
end

it "test_updated_values" do
config_fetcher = ConfigFetcherCountMock.new()
config_cache = InMemoryConfigCache.new()
Expand All @@ -57,6 +61,7 @@
expect(config).to eq 20
cache_policy.stop()
end

it "test_http_error" do
config_fetcher = ConfigFetcherWithErrorMock.new(StandardError.new("error"))
config_cache = InMemoryConfigCache.new()
Expand All @@ -65,6 +70,7 @@
expect(value).to be nil
cache_policy.stop()
end

it "test_stop" do
config_fetcher = ConfigFetcherCountMock.new()
config_cache = InMemoryConfigCache.new()
Expand All @@ -77,6 +83,7 @@
expect(config).to eq 10
cache_policy.stop()
end

it "test_rerun" do
config_fetcher = ConfigFetcherMock.new()
config_cache = InMemoryConfigCache.new()
Expand All @@ -85,6 +92,7 @@
expect(config_fetcher.get_call_count).to eq 2
cache_policy.stop()
end

it "test_callback" do
call_counter = CallCounter.new()
config_fetcher = ConfigFetcherMock.new()
Expand Down

0 comments on commit 765622e

Please sign in to comment.