From: Tom Hughes Date: Thu, 19 Jul 2007 13:22:15 +0000 (+0000) Subject: Fixed error handling in the name search and tidied things up a bit. X-Git-Tag: live~8300 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/77d2fcf9dd80a57e2748ff4a57fb1d603562b9e9?hp=4d1633585feddb414a967f0df83be5c63cc0ffad;ds=sidebyside Fixed error handling in the name search and tidied things up a bit. --- diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8444311b5..76b157faa 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -5,24 +5,12 @@ class GeocoderController < ApplicationController require 'rexml/document' def search - - if params[:postcode] - unless params[:postcode].empty? - postcode = params[:postcode] - check_postcode(postcode) - return - end - end - if params[:query][:postcode] - unless params[:query][:postcode].empty? - postcode =params[:query][:postcode] - check_postcode(postcode) - return - end - end - if params[:query][:place_name] - @place_name = params[:query][:place_name] - redirect_to :controller => 'geocoder', :action => 'results', :params => {:place_name => @place_name} + if params[:postcode] and not params[:postcode].empty? + check_postcode(params[:postcode]) + elsif params[:query][:postcode] and not params[:query][:postcode].empty? + check_postcode(params[:query][:postcode]) + elsif params[:query][:place_name] + redirect_to :controller => 'geocoder', :action => 'results', :params => {:place_name => params[:query][:place_name]} end end @@ -134,9 +122,12 @@ class GeocoderController < ApplicationController @res_ary << res_hash end end - rescue - #Flash a notice to say that geonames is broken - redirect_to "/index.html" + + flash.delete(:notice) + rescue Timeout::Error + flash[:notice] = "Timed out waiting for results from ws.geonames.org" + rescue Exception => ex + flash[:notice] = "Error contacting ws.geonames.org: #{ex.to_s}" end end end