Skip to content
Snippets Groups Projects
Commit cdfb7e31 authored by Caue Guerra's avatar Caue Guerra
Browse files

adding over quota exception handling for nominatim

parent 66a0a118
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,14 @@ module Geocoder::Lookup
doc.is_a?(Array) ? doc : [doc]
end
def parse_raw_data(raw_data)
if raw_data.include?("Bandwidth limit exceeded")
raise_error(Geocoder::OverQueryLimitError) || warn("Over API query limit.")
else
super(raw_data)
end
end
def query_url_params(query)
params = {
:format => "json",
......
<html>\n<head>\n<title>Bandwidth limit exceeded</title>\n</head>\n<body>\n<h1>Bandwidth limit exceeded</h1>\n\n<p>You have been temporarily blocked because you have been overusing OSM's geocoding service or because you have not provided sufficient identification of your application. This block will be automatically lifted after a while. Please take the time and adapt your scripts to reduce the number of requests and make sure that you send a valid UserAgent or Referer.</p>\n\n<p>For more information, consult the <a href=\"http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy\">usage policy</a> for the OSM Nominatim server.\n</body>\n</head>\n
......@@ -20,4 +20,12 @@ class NominatimTest < Test::Unit::TestCase
query = Geocoder::Query.new("Bluffton, SC")
assert_match %r(http://local\.com), query.url
end
def test_raises_exception_when_over_query_limit
Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError])
l = Geocoder::Lookup.get(:nominatim)
assert_raises Geocoder::OverQueryLimitError do
l.send(:results, Geocoder::Query.new("over limit"))
end
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