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

Fixes issue #5660: Failsafe exception returns text/html and text/plain. #7636

Merged
merged 1 commit into from Oct 2, 2012

Conversation

steveklabnik
Copy link
Member

If the request format is text/html then return the existing failsafe
response. For all other formats return text/plain.

The original issue points out to return JSON at the appropriate time,
however as @wycats pointed out, it's often better to return text/plain.

@@ -47,7 +54,7 @@ def render_exception(env, exception)
response[1]['X-Cascade'] == 'pass' ? pass_response(status) : response
rescue Exception => failsafe_error
$stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}"
FAILSAFE_RESPONSE
env['HTTP_ACCEPT'] == 'text/html' ? FAILSAFE_RESPONSE_HTML : FAILSAFE_RESPONSE_PLAIN_TEXT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be =~ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have to be, but that's probably better.

@josevalim
Copy link
Contributor

Nah, in theory this should never be triggered, so I am lazy to keep two versions. Why not just always return text/plain then?

@steveklabnik
Copy link
Member Author

I can also make that change, if you think it's better. The only advantage of returning text/html sometimes is that it'd be prettier for browsers.

@steveklabnik
Copy link
Member Author

Updated. Now we only return text/plain.

@rafaelfranca
Copy link
Member

cc/ @josevalim

@rafaelfranca
Copy link
Member

@steveklabnik could you add a CHANGELOG entry? I'll merge this one.

@steveklabnik
Copy link
Member Author

@rafaelfranca done.

@rafaelfranca
Copy link
Member

This pull request cannot be automatically merged.

@steveklabnik
Copy link
Member Author

Yeah I'm an idiot, fixing now.

It's best to just return text/plain when something has gone terribly
wrong.

Fixes rails#5660.
rafaelfranca added a commit that referenced this pull request Oct 2, 2012
Fixes issue #5660: Failsafe exception returns text/html and text/plain.
@rafaelfranca rafaelfranca merged commit 0d41d69 into rails:master Oct 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants