diff --git a/lib/api_cache.rb b/lib/api_cache.rb index 31da3ba..c00b5a7 100644 --- a/lib/api_cache.rb +++ b/lib/api_cache.rb @@ -51,13 +51,14 @@ def self.get(key, options = {}, &block) value = api.get(key, options[:timeout], &block) cache.set(key, value) value - rescue APICache::CannotFetch - APICache.logger.log "Failed to fetch new data from API" + rescue APICache::CannotFetch => e + APICache.logger.log "Failed to fetch new data from API because " \ + "#{e.class}: #{e.message}" if cache_state == :refetch cache.get(key) else APICache.logger.log "Data not available in the cache or from API" - raise APICache::NotAvailableError + raise APICache::NotAvailableError, e.message end end end diff --git a/lib/api_cache/api.rb b/lib/api_cache/api.rb index 13b10e9..78903e3 100644 --- a/lib/api_cache/api.rb +++ b/lib/api_cache/api.rb @@ -46,8 +46,8 @@ def get(key, timeout, &block) get_via_http(key, timeout) end end - rescue Timeout::Error, APICache::Invalid - raise APICache::CannotFetch + rescue Timeout::Error, APICache::Invalid => e + raise APICache::CannotFetch, e.message end private @@ -59,7 +59,7 @@ def get_via_http(key, timeout) # 2xx response code response.body else - raise APICache::Invalid + raise APICache::Invalid, "Invalid http response: #{response.code}" end end end