mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #14090 from Fortisque/kevin/stream_error_in_main_thread_if_not_committed
re-raise error if error occurs before committing in streaming
This commit is contained in:
commit
ba3ad256c6
2 changed files with 30 additions and 10 deletions
|
@ -228,18 +228,19 @@ module ActionController
|
|||
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
|
||||
|
|
|
@ -153,6 +153,11 @@ module ActionController
|
|||
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 @@ module ActionController
|
|||
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 @@ module ActionController
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue