Skip to content

Commit

Permalink
Propagate error messages downwards to make errors easier to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mloughran committed Mar 30, 2009
1 parent 47fceb5 commit 5c0f3c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/api_cache.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/api_cache/api.rb
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 5c0f3c8

Please sign in to comment.