Permalink
Browse files

Failsafe exception returns text/plain.

It's best to just return text/plain when something has gone terribly
wrong.

Fixes #5660.
  • Loading branch information...
1 parent cfc0ca0 commit 561edbe71ff70abc3c0c63c6c05770b434f9b0a9 @steveklabnik steveklabnik committed Jul 6, 2012
View
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Failsafe exception returns text/plain. *Steve Klabnik*
+
* Remove actionpack's rack-cache dependency and declare the
dependency in the Gemfile.
@@ -15,11 +15,11 @@ module ActionDispatch
# If any exception happens inside the exceptions app, this middleware
# catches the exceptions and returns a FAILSAFE_RESPONSE.
class ShowExceptions
- FAILSAFE_RESPONSE = [500, {'Content-Type' => 'text/html'},
- ["<html><body><h1>500 Internal Server Error</h1>" <<
+ 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.</body></html>"]]
+ "went wrong."]]
def initialize(app, exceptions_app)
@app = app
@@ -93,4 +93,20 @@ def test_render_fallback_exception
assert_equal 'text/html', response.content_type.to_s
end
end
+
+ class ShowFailsafeExceptionsTest < ActionDispatch::IntegrationTest
+ def test_render_failsafe_exception
+ @app = ShowExceptionsOverridenController.action(:boom)
+ @exceptions_app = @app.instance_variable_get(:@exceptions_app)
+ @app.instance_variable_set(:@exceptions_app, nil)
+ $stderr = StringIO.new
+
+ get '/', {}, 'HTTP_ACCEPT' => 'text/json'
+ assert_response :internal_server_error
+ assert_equal 'text/plain', response.content_type.to_s
+
+ @app.instance_variable_set(:@exceptions_app, @exceptions_app)
+ $stderr = STDERR
+ end
+ end
end

0 comments on commit 561edbe

Please sign in to comment.