Add more logs for mapzen services
This commit is contained in:
parent
46c96e02b4
commit
3cc4e06420
@ -57,9 +57,14 @@ class HereMapsRoutingIsoline:
|
||||
return []
|
||||
else:
|
||||
self._logger.error('Error trying to calculate HERE isolines',
|
||||
data={"response": response.json(), "source":
|
||||
source, "mode": mode, "data_range":
|
||||
data_range, "range_type": range_type,
|
||||
data={"response_status": response.status_code,
|
||||
"response_reason": response.reason,
|
||||
"response_content": response.text,
|
||||
"reponse_url": response.url,
|
||||
"response_headers": response.headers,
|
||||
"source": source, "mode": mode,
|
||||
"data_range": data_range,
|
||||
"range_type": range_type,
|
||||
"options": options})
|
||||
raise Exception('Error trying to calculate HERE isolines')
|
||||
|
||||
|
@ -19,14 +19,32 @@ class MapzenGeocoder:
|
||||
|
||||
@qps_retry
|
||||
def geocode(self, searchtext, city=None, state_province=None, country=None):
|
||||
request_params = self._build_requests_parameters(searchtext, city, state_province, country)
|
||||
response = requests.get(self._url, params=request_params)
|
||||
if response.status_code == requests.codes.ok:
|
||||
return self.__parse_response(response.text)
|
||||
elif response.status_code == requests.codes.bad_request:
|
||||
request_params = self._build_requests_parameters(searchtext, city,
|
||||
state_province,
|
||||
country)
|
||||
try:
|
||||
response = requests.get(self._url, params=request_params)
|
||||
if response.status_code == requests.codes.ok:
|
||||
return self.__parse_response(response.text)
|
||||
elif response.status_code == requests.codes.bad_request:
|
||||
return []
|
||||
else:
|
||||
self._logger.error('Error trying to geocode using mapzen',
|
||||
data={"response_status": response.status_code,
|
||||
"response_reason": response.reason,
|
||||
"response_content": response.text,
|
||||
"reponse_url": response.url,
|
||||
"response_headers": response.headers,
|
||||
"searchtext": searchtext,
|
||||
"city": city, "country": country,
|
||||
"state_province": state_province })
|
||||
raise Exception('Error trying to geocode {0} using mapzen'.format(searchtext))
|
||||
except requests.ConnectionError as e:
|
||||
# Don't raise the exception to continue with the geocoding job
|
||||
self._logger.error('Error connecting to Mapzen geocoding server',
|
||||
exception=e)
|
||||
return []
|
||||
else:
|
||||
raise Exception('Error trying to geocode {0} using mapzen'.format(searchtext))
|
||||
|
||||
|
||||
def _build_requests_parameters(self, searchtext, city=None,
|
||||
state_province=None, country=None):
|
||||
|
@ -44,8 +44,13 @@ class MatrixClient:
|
||||
|
||||
if not requests.codes.ok:
|
||||
self._logger.error('Error trying to get matrix distance from mapzen',
|
||||
data={"response": response, "locations":
|
||||
locations, "costing": costing})
|
||||
data={"response_status": response.status_code,
|
||||
"response_reason": response.reason,
|
||||
"response_content": response.text,
|
||||
"reponse_url": response.url,
|
||||
"response_headers": response.headers,
|
||||
"locations": locations,
|
||||
"costing": costing})
|
||||
raise Exception('Error trying to get matrix distance from mapzen')
|
||||
|
||||
return response.json()
|
||||
|
@ -26,7 +26,8 @@ class QPSService:
|
||||
try:
|
||||
return fn(*args, **kwargs)
|
||||
except Exception as e:
|
||||
if hasattr(e, 'response') and (e.response.status_code == 429):
|
||||
response = getattr(e, 'response', None)
|
||||
if response and (response.status_code == 429):
|
||||
self.retry(start_time, attempt_number)
|
||||
else:
|
||||
raise e
|
||||
|
@ -49,11 +49,15 @@ class MapzenRouting:
|
||||
elif response.status_code == requests.codes.bad_request:
|
||||
return MapzenRoutingResponse(None, None, None)
|
||||
else:
|
||||
self._logger.error('Error trying to calculate route using HERE',
|
||||
data={"response": response.json(), "waypoints":
|
||||
waypoints, "mode": mode, "options":
|
||||
options})
|
||||
raise Exception('Error trying to calculate route using HERE')
|
||||
self._logger.error('Error trying to calculate route using Mapzen',
|
||||
data={"response_status": response.status_code,
|
||||
"response_reason": response.reason,
|
||||
"response_content": response.text,
|
||||
"reponse_url": response.url,
|
||||
"response_headers": response.headers,
|
||||
"waypoints": waypoints, "mode": mode,
|
||||
"options": options})
|
||||
raise Exception('Error trying to calculate route using Mapzen')
|
||||
|
||||
def __parse_options(self, options):
|
||||
return dict(option.split('=') for option in options)
|
||||
|
@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
||||
setup(
|
||||
name='cartodb_services',
|
||||
|
||||
version='0.7.4.1',
|
||||
version='0.7.4.2',
|
||||
|
||||
description='CartoDB Services API Python Library',
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user