From d53978539c71d598d7cb5f47ad9e3f30a83eb06a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 2 May 2018 19:27:39 +0200 Subject: RouteWayCostCalculator: Don't update `costs` if response errors If there's an API error, we shouldn't update the route's `costs` field. Let's say we've already calculated some costs for a route A. We then edit and re-save A, which triggers a recalculation of the costs. Now the TomTom API responds with an error. We don't want to overwrite our existing costs with an empty array because they could still be useful. In this case, we should instead keep the existing costs we already had. To achieve this, move the `RemoteError` rescue into `RouteWayCostCalculator`, leaving the error unhandled in `TomTom.matrix`. Refs #6884 --- lib/tom_tom/matrix.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index b57495f3f..75c2cc02b 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -4,6 +4,10 @@ module TomTom @connection = connection end + # Exceptions: + # + # * This raises a `TomTom::Matrix::RemoteError` when the API responds with + # an error. def matrix(way_costs) points_with_ids = points_from_way_costs(way_costs) points = points_as_params(points_with_ids) @@ -29,10 +33,6 @@ module TomTom points_with_ids, matrix_json ) - rescue RemoteError => e - Rails.logger.error "TomTom::Matrix server error: #{e}" - - [] end def points_from_way_costs(way_costs) -- cgit v1.2.3