lib/geocoder/lookups/bing.rb in geocoder-1.2.8 vs lib/geocoder/lookups/bing.rb in geocoder-1.2.9
- old
+ new
@@ -56,17 +56,25 @@
}.merge(super)
end
def check_response_for_errors!(response)
super
- if response['x-ms-bm-ws-info'].to_i == 1
- # Occasionally, the servers processing service requests can be overloaded,
- # and you may receive some responses that contain no results for queries that
- # you would normally receive a result. To identify this situation,
- # check the HTTP headers of the response. If the HTTP header X-MS-BM-WS-INFO is set to 1,
- # it is best to wait a few seconds and try again.
+ if server_overloaded?(response)
raise_error(Geocoder::ServiceUnavailable) ||
Geocoder.log(:warn, "Bing Geocoding API error: Service Unavailable")
end
+ end
+
+ def valid_response?(response)
+ super(response) and not server_overloaded?(response)
+ end
+
+ def server_overloaded?(response)
+ # Occasionally, the servers processing service requests can be overloaded,
+ # and you may receive some responses that contain no results for queries that
+ # you would normally receive a result. To identify this situation,
+ # check the HTTP headers of the response. If the HTTP header X-MS-BM-WS-INFO is set to 1,
+ # it is best to wait a few seconds and try again.
+ response['x-ms-bm-ws-info'].to_i == 1
end
end
end