From: Tom Hughes Date: Mon, 20 Aug 2007 14:22:51 +0000 (+0000) Subject: Handle errors a bit better. X-Git-Tag: live~8162 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/9738e3f6482972ccf68b9b2e92ad498a31ccb6d8 Handle errors a bit better. --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index f7b56e769..d84059874 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -108,11 +108,14 @@ class TraceController < ApplicationController def data trace = Trace.find(params[:id]) - if trace and (trace.public? or (@user and @user == trace.user)) + + if trace.public? or (@user and @user == trace.user) send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment') else render :nothing, :status => :not_found end + rescue ActiveRecord::RecordNotFound + render :nothing => true, :status => :not_found end def make_public @@ -153,10 +156,14 @@ class TraceController < ApplicationController def picture trace = Trace.find(params[:id]) - if trace.public? or (@user and @user == trace.user) - send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') + if trace.inserted? + if trace.public? or (@user and @user == trace.user) + send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') + else + render :nothing, :status => :forbidden + end else - render :nothing, :status => :forbidden + render :nothing => true, :status => :not_found end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found @@ -165,10 +172,14 @@ class TraceController < ApplicationController def icon trace = Trace.find(params[:id]) - if trace.public? or (@user and @user == trace.user) - send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') + if trace.inserted? + if trace.public? or (@user and @user == trace.user) + send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') + else + render :nothing, :status => :forbidden + end else - render :nothing, :status => :forbidden + render :nothing => true, :status => :not_found end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found diff --git a/app/controllers/way_controller.rb b/app/controllers/way_controller.rb index d6489fef8..e7d6cf87b 100644 --- a/app/controllers/way_controller.rb +++ b/app/controllers/way_controller.rb @@ -142,7 +142,11 @@ class WayController < ApplicationController end def ways - ids = params['ways'].split(',').collect { |w| w.to_i } + begin + ids = params['ways'].split(',').collect { |w| w.to_i } + rescue + ids = [] + end if ids.length > 0 doc = OSM::API.new.get_xml_doc