Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streaming should change status of response when exception is caught #14000

Merged
merged 1 commit into from Feb 18, 2014

Conversation

kacasey8
Copy link
Contributor

@kacasey8 kacasey8 commented Feb 9, 2014

This fixes #12552. #9604 looks like sgrif expected that if streaming and an exception occurs we should just log it and in the view use javascript to display a 500 error while bkudria is saying that we should change the status response (not a 200 for correctly rendering an error message).

@kacasey8
Copy link
Contributor Author

kacasey8 commented Feb 9, 2014

@tenderlove @matthewd

@tenderlove
Copy link
Member

@Fortisque this fix is going on the wrong direction, I think.

This is where the controller is called and the template is processed (of course you found that). But if either controller processing or template processing raises an exception, we just need to set the response status.

In the simplest case, it should look like this:

diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb
index 33014b9..6fb3e44 100644
--- a/actionpack/lib/action_controller/metal/live.rb
+++ b/actionpack/lib/action_controller/metal/live.rb
@@ -205,6 +205,7 @@ module ActionController
         begin
           super(name)
         rescue => e
+          @_response.status = 500 unless @_response.committed?
           begin
             @_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
             @_response.stream.call_on_error

The above patch will fix the reporter's test case. But you should also rescue an ActionController::BadRequest and convert it to a 400 response. Try integrating the reporter's test case in to the actionpack tests and add this fix. Then add a new test case that raises a BadRequest exception and fix that too.

Does it make sense?

@kacasey8
Copy link
Contributor Author

Yeah that makes sense, I've modified my commit.

@tenderlove
Copy link
Member

One more change: change your commit message and add "fixes #12552". If you do that, when I push your changes to the Rails repository, it will automatically close the ticket.

@kacasey8
Copy link
Contributor Author

I think resolve does the same thing in github at least, I'll change it though

@robin850
Copy link
Member

Also could you add a changelog entry as well please ? Nice work though, thank you!

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)
tenderlove added a commit that referenced this pull request Feb 18, 2014
streaming should change status of response when exception is caught
@tenderlove tenderlove merged commit f430836 into rails:master Feb 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Including ActionController::Live causes a controller to swallow all errors and return 200 always
3 participants