Added new logger to all the functions
This commit is contained in:
@@ -12,9 +12,10 @@ class MapzenGeocoder:
|
||||
|
||||
BASE_URL = 'https://search.mapzen.com/v1/search'
|
||||
|
||||
def __init__(self, app_key, base_url=BASE_URL):
|
||||
def __init__(self, app_key, logger, base_url=BASE_URL):
|
||||
self._app_key = app_key
|
||||
self._url = base_url
|
||||
self._logger = logger
|
||||
|
||||
@qps_retry
|
||||
def geocode(self, searchtext, city=None, state_province=None, country=None):
|
||||
@@ -25,7 +26,7 @@ class MapzenGeocoder:
|
||||
elif response.status_code == requests.codes.bad_request:
|
||||
return []
|
||||
else:
|
||||
response.raise_for_status()
|
||||
raise Exception('Error trying to geocode {0} using mapzen'.format(searchtext))
|
||||
|
||||
def _build_requests_parameters(self, searchtext, city=None,
|
||||
state_province=None, country=None):
|
||||
|
||||
@@ -2,6 +2,7 @@ import requests
|
||||
import json
|
||||
from qps import qps_retry
|
||||
|
||||
|
||||
class MatrixClient:
|
||||
|
||||
"""
|
||||
@@ -42,8 +43,14 @@ class MatrixClient:
|
||||
response = requests.get(self.ONE_TO_MANY_URL, params=request_params)
|
||||
|
||||
if not requests.codes.ok:
|
||||
self._logger.warning('Error trying to get matrix distance from mapzen', data={"response": response, "locations": locations, "costing": costing})
|
||||
|
||||
response.raise_for_status() # raise exception if not 200 OK
|
||||
self._logger.error('Error trying to get matrix distance from mapzen',
|
||||
data={"response": response.json(), "locations":
|
||||
locations, "costing": costing})
|
||||
raise Exception('Error trying to get matrix distance from mapzen')
|
||||
else:
|
||||
self._logger.debug('Done get matrix distance from mapzen',
|
||||
data={"response": response.json(),
|
||||
"locations": locations,
|
||||
"costing": costing})
|
||||
|
||||
return response.json()
|
||||
|
||||
@@ -28,9 +28,10 @@ class MapzenRouting:
|
||||
METRICS_UNITS = 'kilometers'
|
||||
IMPERIAL_UNITS = 'miles'
|
||||
|
||||
def __init__(self, app_key, base_url=PRODUCTION_ROUTING_BASE_URL):
|
||||
def __init__(self, app_key, logger, base_url=PRODUCTION_ROUTING_BASE_URL):
|
||||
self._app_key = app_key
|
||||
self._url = base_url
|
||||
self._logger = logger
|
||||
|
||||
@qps_retry
|
||||
def calculate_route_point_to_point(self, waypoints, mode,
|
||||
@@ -48,7 +49,11 @@ class MapzenRouting:
|
||||
elif response.status_code == requests.codes.bad_request:
|
||||
return MapzenRoutingResponse(None, None, None)
|
||||
else:
|
||||
response.raise_for_status()
|
||||
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')
|
||||
|
||||
def __parse_options(self, options):
|
||||
return dict(option.split('=') for option in options)
|
||||
|
||||
Reference in New Issue
Block a user