From: Tom Hughes Date: Wed, 30 Sep 2015 20:56:57 +0000 (+0100) Subject: Improve error handling for routing engines X-Git-Tag: live~3969 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/3c771a7844fe6d8536eae0a8c9f544059b7eb001 Improve error handling for routing engines --- diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index a5f3b0080..a141045a3 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -189,7 +189,7 @@ OSM.Directions = function (map) { map.removeLayer(polyline); if (!dragging) { - alert(I18n.t('javascripts.directions.errors.no_route')); + $('#sidebar_content').html('

' + I18n.t('javascripts.directions.errors.no_route') + '

'); } return; diff --git a/app/assets/javascripts/index/directions/graphhopper.js b/app/assets/javascripts/index/directions/graphhopper.js index 5a16f708c..2d3455eee 100644 --- a/app/assets/javascripts/index/directions/graphhopper.js +++ b/app/assets/javascripts/index/directions/graphhopper.js @@ -58,12 +58,15 @@ function GraphHopperEngine(id, vehicleType) { ]); // TODO does graphhopper map instructions onto line indices? } - callback(null, { + callback(false, { line: line, steps: steps, distance: path.distance, time: path.time / 1000 }); + }, + error: function () { + callback(true); } }); } diff --git a/app/assets/javascripts/index/directions/mapquest.js b/app/assets/javascripts/index/directions/mapquest.js index 24be65de7..f46d94dcf 100644 --- a/app/assets/javascripts/index/directions/mapquest.js +++ b/app/assets/javascripts/index/directions/mapquest.js @@ -83,12 +83,15 @@ function MapQuestEngine(id, routeType) { steps.push([L.latLng(s.startPoint.lat, s.startPoint.lng), d, s.narrative, s.distance * 1000, lineseg]); } - callback(null, { + callback(false, { line: line, steps: steps, distance: data.route.distance * 1000, time: data.route.time }); + }, + error: function () { + callback(true); } }); } diff --git a/app/assets/javascripts/index/directions/mapzen.js b/app/assets/javascripts/index/directions/mapzen.js index 915e665f5..02f0f4188 100644 --- a/app/assets/javascripts/index/directions/mapzen.js +++ b/app/assets/javascripts/index/directions/mapzen.js @@ -93,6 +93,9 @@ function MapzenEngine(id, costing) { } else { callback(true); } + }, + error: function () { + callback(true); } }); } diff --git a/app/assets/javascripts/index/directions/osrm.js b/app/assets/javascripts/index/directions/osrm.js index ab3bcff36..4a42d5dc9 100644 --- a/app/assets/javascripts/index/directions/osrm.js +++ b/app/assets/javascripts/index/directions/osrm.js @@ -84,12 +84,15 @@ function OSRMEngine() { steps.push([line[s[3]], s[0].split('-')[0], instText, s[2], line.slice(s[3], linesegend)]); } - callback(null, { + callback(false, { line: line, steps: steps, distance: data.route_summary.total_distance, time: data.route_summary.total_time }); + }, + error: function () { + callback(true); } }); }