From a791d02dccbc8298960aa98a275953ca8c4744de Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Fri, 2 Feb 2018 13:26:29 +0100 Subject: [PATCH] 422 errors from mapbox return empty response --- .../cartodb_services/cartodb_services/mapbox/geocoder.py | 2 ++ .../cartodb_services/cartodb_services/mapbox/isolines.py | 5 +++++ .../cartodb_services/mapbox/matrix_client.py | 2 ++ .../cartodb_services/cartodb_services/mapbox/routing.py | 2 ++ 4 files changed, 11 insertions(+) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py index ceba105..8d7cacb 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py @@ -80,6 +80,8 @@ class MapboxGeocoder(Traceable): return self._parse_geocoder_response(response.text) elif response.status_code == requests.codes.bad_request: return [] + elif response.status_code == requests.codes.unprocessable_entity: + return [] else: raise ServiceException(response.status_code, response) except requests.Timeout as te: diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py index 10c4209..e7f06c1 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py @@ -49,6 +49,8 @@ class MapboxIsolines(): response = self._matrix_client.matrix([origin] + targets, profile) json_response = json.loads(response) + if not json_response: + return [] costs = [None] * number_of_angles @@ -125,6 +127,9 @@ class MapboxIsolines(): unit_factor=unit_factor, number_of_angles=number_of_angles) + if not costs: + continue + errors = [(cost - isorange) / float(isorange) for cost in costs] max_abs_error = max([abs(e) for e in errors]) if max_abs_error <= tolerance: diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py index dfe0bde..8d547b6 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py @@ -72,6 +72,8 @@ class MapboxMatrixClient(Traceable): return response.text elif response.status_code == requests.codes.bad_request: return '{}' + elif response.status_code == requests.codes.unprocessable_entity: + return '{}' else: raise ServiceException(response.status_code, response) except requests.Timeout as te: diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py index e0827ca..3f30268 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/routing.py @@ -91,6 +91,8 @@ class MapboxRouting(Traceable): return self._parse_routing_response(response.text) elif response.status_code == requests.codes.bad_request: return MapboxRoutingResponse(None, None, None) + elif response.status_code == requests.codes.unprocessable_entity: + return MapboxRoutingResponse(None, None, None) else: raise ServiceException(response.status_code, response) except requests.Timeout as te: