aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Perles2016-01-11 13:40:15 +0100
committerBruno Perles2016-01-11 13:40:15 +0100
commit0ca7af85435c326a5da9e689a37872dad5a492c1 (patch)
tree815c4fa2b0f269b144a71a216552c8948b135075
parent70b294fa52cd5fb632c124d5f847645ba8ff6d0f (diff)
downloadchouette-core-0ca7af85435c326a5da9e689a37872dad5a492c1.tar.bz2
Add condition to prevent app crash
-rw-r--r--app/views/route_sections/edit.html.erb2
-rw-r--r--lib/osrm_route_section_processor.rb3
2 files changed, 3 insertions, 2 deletions
diff --git a/app/views/route_sections/edit.html.erb b/app/views/route_sections/edit.html.erb
index 80b7bde4a..1e8133344 100644
--- a/app/views/route_sections/edit.html.erb
+++ b/app/views/route_sections/edit.html.erb
@@ -1,4 +1,4 @@
<%= title_tag t('route_sections.edit.title') %>
-<%= @map.to_html %>
+<%= @map.to_html if @map %>
<%= render "form" %>
diff --git a/lib/osrm_route_section_processor.rb b/lib/osrm_route_section_processor.rb
index 972f070d0..5f3bdef29 100644
--- a/lib/osrm_route_section_processor.rb
+++ b/lib/osrm_route_section_processor.rb
@@ -10,8 +10,9 @@ class OsrmRouteSectionProcessor
Rails.logger.info "Invoke router.project-osrm.org for RouteSection StopArea:#{route_section.departure.id} -> StopArea:#{route_section.arrival.id}"
response = open "http://router.project-osrm.org/viaroute?#{points_string}instructions=false"
- geometry = JSON.parse(response.read.to_s)['route_geometry']
+ return nil unless response
+ geometry = JSON.parse(response.read.to_s)['route_geometry']
if geometry
decoded_geometry = Polylines::Decoder.decode_polyline(geometry, 1e6).map do |point|
GeoRuby::SimpleFeatures::Point.from_x_y(point[1], point[0], 4326)