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 --- app/services/route_way_cost_calculator.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/services') diff --git a/app/services/route_way_cost_calculator.rb b/app/services/route_way_cost_calculator.rb index d41a2e59a..58f9ad1d0 100644 --- a/app/services/route_way_cost_calculator.rb +++ b/app/services/route_way_cost_calculator.rb @@ -8,5 +8,7 @@ class RouteWayCostCalculator way_costs = TomTom.matrix(way_costs) way_costs = WayCostCollectionJSONSerializer.dump(way_costs) @route.update(costs: way_costs) + rescue TomTom::Matrix::RemoteError => e + Rails.logger.error "TomTom::Matrix server error: #{e}" end end -- cgit v1.2.3