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') 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 From 9c442cd66c7d12266ba53e85949f775f6b842d2d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 4 May 2018 12:49:06 +0200 Subject: Move `TomTom::Matrix::RemoteError` to`TomTom::Errors::MatrixRemoteError` I previously tried to correct a circular dependency problem in a057276129b1f62b811743db3b8f867a05241ed3, but that didn't fix it (it was intermittent, and came back). After some wrangling, I've now deduced with some confidence that the problem comes from `RouteWayCostCalculator`, which used `TomTom::Matrix::RemoteError`. From the way it looks, this seems to mess up the Rails autoloader since `tom_tom.rb` will try to load the `Matrix` class from the `TomTom.matrix` call above. Or something. In an attempt to fix the circular dependency error for real this time, move the error class to a completely separate module from `Matrix`, and refer to this when we need to use the error class. Refs #6884 --- app/services/route_way_cost_calculator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/services/route_way_cost_calculator.rb b/app/services/route_way_cost_calculator.rb index 58f9ad1d0..ca47a6772 100644 --- a/app/services/route_way_cost_calculator.rb +++ b/app/services/route_way_cost_calculator.rb @@ -8,7 +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 + rescue TomTom::Errors::MatrixRemoteError => e Rails.logger.error "TomTom::Matrix server error: #{e}" end end -- cgit v1.2.3