Skip to content

Commit

Permalink
Fixed a subtle issue with rescueing NoMethodFound exceptions inside o…
Browse files Browse the repository at this point in the history
…f the dispatching method and treating it like a 404. This is because any action could raise a NoMethodFound too. Much more careful and explicit, but no false positives should arise from this now.
  • Loading branch information
mtodd committed Apr 17, 2008
1 parent df08185 commit 075636d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/halcyon/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,20 @@ def dispatch(env)
Object.const_get(route[:controller].camel_case.to_sym).new(env)
end

controller.send((route[:action] || 'default').to_sym)
rescue NoMethodError => e
raise NotFound.new
# This block and the following call to +action+ detects if a non-
# existent action is routed to, as opposed to just catching a blanket
# <tt>NoMethodFound</tt> error which can occur in actions too,
# reporting as a <tt>404 Not Found error</tt> incorrectly.
begin
action = controller.method((route[:action] || 'default').to_sym)
rescue NameError => e
raise NotFound.new
end

# Calls the action. This will only run if the action exists inside of
# the controller and won't throw false positives for bad method calls
# in the action as a <tt>404 Not Found</tt> error.
action.call
rescue NameError => e
raise NotFound.new
end
Expand Down

0 comments on commit 075636d

Please sign in to comment.