Skip to content

Commit

Permalink
Avoid returning a constant in ActionDispatch::ShowExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiculescu authored and jeremy committed Aug 26, 2021
1 parent 6e9304a commit 326d886
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions actionpack/lib/action_dispatch/middleware/show_exceptions.rb
Expand Up @@ -14,14 +14,8 @@ module ActionDispatch
# If the application returns a "X-Cascade" pass response, this middleware
# will send an empty response as result with the correct status code.
# If any exception happens inside the exceptions app, this middleware
# catches the exceptions and returns a FAILSAFE_RESPONSE.
# catches the exceptions and returns a failsafe response.
class ShowExceptions
FAILSAFE_RESPONSE = [500, { "Content-Type" => "text/plain" },
["500 Internal Server Error\n" \
"If you are the administrator of this website, then please read this web " \
"application's log file and/or the web server's log file to find out what " \
"went wrong."]]

def initialize(app, exceptions_app)
@app = app
@exceptions_app = exceptions_app
Expand Down Expand Up @@ -52,7 +46,12 @@ def render_exception(request, exception)
response[1]["X-Cascade"] == "pass" ? pass_response(status) : response
rescue Exception => failsafe_error
$stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}"
FAILSAFE_RESPONSE

[500, { "Content-Type" => "text/plain" },
["500 Internal Server Error\n" \
"If you are the administrator of this website, then please read this web " \
"application's log file and/or the web server's log file to find out what " \
"went wrong."]]
end

def pass_response(status)
Expand Down

0 comments on commit 326d886

Please sign in to comment.