Skip to content

Commit

Permalink
Refactor to handle the X-Cascade without having to raise an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
krekoten authored and jeremy committed Jan 10, 2011
1 parent 3e24655 commit 366e785
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions actionpack/lib/action_dispatch/middleware/show_exceptions.rb
Expand Up @@ -43,20 +43,20 @@ def initialize(app, consider_all_requests_local = false)
end

def call(env)
status, headers, body = @app.call(env)

# Only this middleware cares about RoutingError. So, let's just raise
# it here.
# TODO: refactor this middleware to handle the X-Cascade scenario without
# having to raise an exception.
if headers['X-Cascade'] == 'pass'
raise ActionController::RoutingError, "No route matches #{env['PATH_INFO'].inspect}"
begin
status, headers, body = @app.call(env)
exception = nil

# Only this middleware cares about RoutingError. So, let's just raise
# it here.
if headers['X-Cascade'] == 'pass'
exception = ActionController::RoutingError.new("No route matches #{env['PATH_INFO'].inspect}")
end
rescue Exception => exception
end

[status, headers, body]
rescue Exception => exception
raise exception if env['action_dispatch.show_exceptions'] == false
render_exception(env, exception)

exception ? render_exception(env, exception) : [status, headers, body]
end

private
Expand Down

0 comments on commit 366e785

Please sign in to comment.