Permalink
Browse files

Gracefully handle reverse geocoding failures

  • Loading branch information...
1 parent 9277a89 commit 5a0750885e1b37bc61bc8a420b8ceeb95644addc @cnorthwood cnorthwood committed Jul 8, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 molly/geolocation/providers/cloudmade.py
@@ -26,12 +26,23 @@ def reverse_geocode(self, lon, lat):
'type': 'road',
}
- data = urllib2.urlopen(self.REVERSE_GEOCODE_URL % params)
-
- json = simplejson.load(data)
+ try:
+ request_url = self.REVERSE_GEOCODE_URL % params
+ response = urllib2.urlopen(request_url)
+ if response.code != 200:
+ logger.error("Request to %s returned response code %d" % (request_url, response.code))
+ return []
+ json = simplejson.loads(response.read().replace(''', "'"), 'utf8')
+ except urllib2.HTTPError, e:
+ logger.error("Cloudmade returned a non-OK response code %d", e.code)
+ return []
+ except urllib2.URLError, e:
+ logger.error("Encountered an error reaching Cloudmade: %s", str(e))
+ return []
if not json:
return []
+
else:
name = json['features'][0]['properties'].get('name')
try:

0 comments on commit 5a07508

Please sign in to comment.