Skip to content
Snippets Groups Projects
Commit 0e157f67 authored by Alex Reisner's avatar Alex Reisner
Browse files

Only cache response if successful.

parent 6e631499
No related branches found
No related tags found
No related merge requests found
......@@ -146,15 +146,16 @@ module Geocoder
timeout(Geocoder::Configuration.timeout) do
url = query_url(query, reverse)
uri = URI.parse(url)
unless cache and response = cache[url]
unless cache and body = cache[url]
client = http_client.new(uri.host, uri.port)
client.use_ssl = true if Geocoder::Configuration.use_https
response = client.get(uri.request_uri).body
if cache
cache[url] = response
response = client.get(uri.request_uri)
body = response.body
if cache and (200..399).include?(response.code.to_i)
cache[url] = body
end
end
response
body
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment