Skip to content
Snippets Groups Projects
Unverified Commit cf37a716 authored by Alex Reisner's avatar Alex Reisner Committed by GitHub
Browse files

Merge pull request #1259 from careport/raise-errors-bing

Raise bing errors for statuses 403, 500, 503
parents 9ea50a86 4dc3b36e
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,11 @@ module Geocoder::Lookup
return doc['resourceSets'].first['estimatedTotal'] > 0 ? doc['resourceSets'].first['resources'] : []
elsif doc['statusCode'] == 401 and doc["authenticationResultCode"] == "InvalidCredentials"
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid Bing API key.")
elsif doc['statusCode'] == 403
raise_error(Geocoder::RequestDenied) || Geocoder.log(:warn, "Bing Geocoding API error: Forbidden Request")
elsif [500, 503].include?(doc['statusCode'])
raise_error(Geocoder::ServiceUnavailable) ||
Geocoder.log(:warn, "Bing Geocoding API error: Service Unavailable")
else
Geocoder.log(:warn, "Bing Geocoding API error: #{doc['statusCode']} (#{doc['statusDescription']}).")
end
......
{
"authenticationResultCode":"ValidCredentials",
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"resourceSets":[
{
"estimatedTotal":0,
"resources":[
]
}
],
"statusCode":403,
"statusDescription":"OK",
"traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397"
}
{
"authenticationResultCode":"ValidCredentials",
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"resourceSets":[
{
"estimatedTotal":0,
"resources":[
]
}
],
"statusCode":500,
"statusDescription":"OK",
"traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397"
}
......@@ -82,4 +82,18 @@ class BingTest < GeocoderTestCase
l.send(:results, Geocoder::Query.new("service unavailable"))
end
end
def test_raises_exception_when_bing_returns_forbidden_request
Geocoder.configure(:always_raise => [Geocoder::RequestDenied])
assert_raises Geocoder::RequestDenied do
Geocoder.search("forbidden request")
end
end
def test_raises_exception_when_bing_returns_internal_server_error
Geocoder.configure(:always_raise => [Geocoder::ServiceUnavailable])
assert_raises Geocoder::ServiceUnavailable do
Geocoder.search("internal server error")
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