Google batch geocoder error handling

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-23 18:41:47 +02:00
parent 4be3aa88fd
commit fc75f1afc8

View File

@ -1,7 +1,7 @@
from multiprocessing import Pool from multiprocessing import Pool
from exceptions import MalformedResult from exceptions import MalformedResult
from cartodb_services import StreetPointBulkGeocoder from cartodb_services import StreetPointBulkGeocoder
from cartodb_services.geocoder import compose_address from cartodb_services.geocoder import compose_address, geocoder_error_response
from cartodb_services.google import GoogleMapsGeocoder from cartodb_services.google import GoogleMapsGeocoder
@ -25,8 +25,13 @@ class GoogleMapsBulkGeocoder(GoogleMapsGeocoder, StreetPointBulkGeocoder):
results = [] results = []
for search in searches: for search in searches:
(cartodb_id, street, city, state, country) = search (cartodb_id, street, city, state, country) = search
lng_lat, metadata = self.geocode_meta(street, city, state, country) try:
results.append((cartodb_id, lng_lat, metadata)) lng_lat, metadata = self.geocode_meta(street, city, state, country)
result = (cartodb_id, lng_lat, metadata)
except Exception as e:
self._logger.error("Error geocoding", e)
result = geocoder_error_response("Error geocoding")
results.append(result)
return results return results
def _batch_geocode(self, searches): def _batch_geocode(self, searches):
@ -49,14 +54,12 @@ class GoogleMapsBulkGeocoder(GoogleMapsGeocoder, StreetPointBulkGeocoder):
try: try:
lng_lat, metadata = self._process_results(bulk_result.get()) lng_lat, metadata = self._process_results(bulk_result.get())
except Exception as e: except Exception as e:
self._logger.error('Error at Google async_geocoder', e) msg = 'Error at Google async_geocoder'
lng_lat, metadata = [[], {}] self._logger.error(msg, e)
lng_lat, metadata = geocoder_error_response(msg)
results.append((cartodb_id, lng_lat, metadata)) results.append((cartodb_id, lng_lat, metadata))
return results return results
except KeyError as e:
self._logger.error('KeyError error', exception=e)
raise MalformedResult()
except Exception as e: except Exception as e:
self._logger.error('General error', exception=e) self._logger.error('General error', exception=e)
raise e raise e