Permalink
Browse files

Merge pull request #14000 from Fortisque/kevin/stream_error_management

streaming should change status of response when exception is caught
  • Loading branch information...
2 parents c18e7ab + 8508346 commit f43083609a0a16f91e5f1cfc98a289a23865aea8 @tenderlove tenderlove committed Feb 18, 2014
View
@@ -1,3 +1,10 @@
+* Set stream status to 500 (or 400 on BadRequest) when an error is thrown
+ before commiting.
+
+ Fixes #12552.
+
+ *Kevin Casey*
+
* Add new config option `config.action_dispatch.cookies_serializer` for
specifying a serializer for the signed and encrypted cookie jars.
@@ -205,6 +205,8 @@ def process(name)
begin
super(name)
rescue => e
+ @_response.status = 500 unless @_response.committed?
+ @_response.status = 400 if e.class == ActionController::BadRequest
begin
@_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
@_response.stream.call_on_error
@@ -156,6 +156,14 @@ def exception_with_callback
raise 'An exception occurred...'
end
+ def exception_in_controller
+ raise 'Exception in controller'
+ end
+
+ def bad_request_error
+ raise ActionController::BadRequest
+ end
+
def exception_in_exception_callback
response.headers['Content-Type'] = 'text/event-stream'
response.stream.on_error do
@@ -275,6 +283,16 @@ def test_exception_callback
end
end
+ def test_exception_in_controller_before_streaming
+ response = get :exception_in_controller, format: 'text/event-stream'
+ assert_equal 500, response.status
+ end
+
+ def test_bad_request_in_controller_before_streaming
+ response = get :bad_request_error, format: 'text/event-stream'
+ assert_equal 400, response.status
+ end
+
def test_exceptions_raised_handling_exceptions
capture_log_output do |output|
get :exception_in_exception_callback, format: 'text/event-stream'

0 comments on commit f430836

Please sign in to comment.