Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #14090 from Fortisque/kevin/stream_error_in_main_t…

…hread_if_not_committed

re-raise error if error occurs before committing in streaming
  • Loading branch information...
commit 11a44632a369c411431af5c1b141831e64112913 1 parent 4c0d668
@tenderlove tenderlove authored
View
21 actionpack/lib/action_controller/metal/live.rb
@@ -228,18 +228,19 @@ def process(name)
begin
super(name)
rescue => e
- unless @_response.committed?
+ if @_response.committed?
+ begin
+ @_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
+ @_response.stream.call_on_error
+ rescue => exception
+ log_error(exception)
+ ensure
+ log_error(e)
+ @_response.stream.close
+ end
+ else
error = e
end
- begin
- @_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
- @_response.stream.call_on_error
- rescue => exception
- log_error(exception)
- ensure
- log_error(e)
- @_response.stream.close
- end
ensure
@_response.commit!
end
View
19 actionpack/test/controller/live_stream_test.rb
@@ -153,6 +153,11 @@ def exception_in_view
render 'doesntexist'
end
+ def exception_in_view_after_commit
+ response.stream.write ""
+ render 'doesntexist'
+ end
+
def exception_with_callback
response.headers['Content-Type'] = 'text/event-stream'
@@ -269,6 +274,13 @@ def test_exception_handling_html
assert_raises(ActionView::MissingTemplate) do
get :exception_in_view
end
+
+ capture_log_output do |output|
+ get :exception_in_view_after_commit
+ assert_match %r((window\.location = "/500\.html"</script></html>)$), response.body
+ assert_match 'Missing template test/doesntexist', output.rewind && output.read
+ assert_stream_closed
+ end
assert response.body
assert_stream_closed
end
@@ -277,6 +289,13 @@ def test_exception_handling_plain_text
assert_raises(ActionView::MissingTemplate) do
get :exception_in_view, format: :json
end
+
+ capture_log_output do |output|
+ get :exception_in_view_after_commit, format: :json
+ assert_equal '', response.body
+ assert_match 'Missing template test/doesntexist', output.rewind && output.read
+ assert_stream_closed
+ end
end
def test_exception_callback_when_committed
Please sign in to comment.
Something went wrong with that request. Please try again.