1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Correct prestreaming controller response status.

if the controller action has not yet streamed any data, actions should
process as normal, and errors should trigger the appropriate behavior
(500, or in the case of ActionController::BadRequest, a 400 Bad Request)
This commit is contained in:
Kevin Casey 2014-02-15 13:05:00 -08:00
parent 4914adc2b0
commit 8508346dd0
3 changed files with 27 additions and 0 deletions

View file

@ -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.

View file

@ -205,6 +205,8 @@ module ActionController
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

View file

@ -156,6 +156,14 @@ module ActionController
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 @@ module ActionController
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'