Add more logs for mapzen services

This commit is contained in:
Mario de Frutos 2016-08-17 11:41:29 +02:00
parent 46c96e02b4
commit 3cc4e06420
6 changed files with 52 additions and 19 deletions

View File

@ -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')

View File

@ -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)
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 []
def _build_requests_parameters(self, searchtext, city=None,
state_province=None, country=None):

View File

@ -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()

View File

@ -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

View File

@ -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)

View File

@ -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',