aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2018-05-02 19:27:39 +0200
committerTeddy Wing2018-05-02 19:27:39 +0200
commitd53978539c71d598d7cb5f47ad9e3f30a83eb06a (patch)
treebfaad8de0ff179d56f7f0c3c7f8a5f7d1decbb2f /app
parentb6c0477552576e7f8575bf2dca6e7899b640c012 (diff)
downloadchouette-core-d53978539c71d598d7cb5f47ad9e3f30a83eb06a.tar.bz2
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
Diffstat (limited to 'app')
-rw-r--r--app/services/route_way_cost_calculator.rb2
1 files changed, 2 insertions, 0 deletions
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