Skip to content

Commit 366e785

Browse files
krekotenjeremy
authored andcommitted
Refactor to handle the X-Cascade without having to raise an exception
1 parent 3e24655 commit 366e785

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

actionpack/lib/action_dispatch/middleware/show_exceptions.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ def initialize(app, consider_all_requests_local = false)
4343
end
4444

4545
def call(env)
46-
status, headers, body = @app.call(env)
47-
48-
# Only this middleware cares about RoutingError. So, let's just raise
49-
# it here.
50-
# TODO: refactor this middleware to handle the X-Cascade scenario without
51-
# having to raise an exception.
52-
if headers['X-Cascade'] == 'pass'
53-
raise ActionController::RoutingError, "No route matches #{env['PATH_INFO'].inspect}"
46+
begin
47+
status, headers, body = @app.call(env)
48+
exception = nil
49+
50+
# Only this middleware cares about RoutingError. So, let's just raise
51+
# it here.
52+
if headers['X-Cascade'] == 'pass'
53+
exception = ActionController::RoutingError.new("No route matches #{env['PATH_INFO'].inspect}")
54+
end
55+
rescue Exception => exception
5456
end
55-
56-
[status, headers, body]
57-
rescue Exception => exception
5857
raise exception if env['action_dispatch.show_exceptions'] == false
59-
render_exception(env, exception)
58+
59+
exception ? render_exception(env, exception) : [status, headers, body]
6060
end
6161

6262
private

0 commit comments

Comments
 (0)