method
failsafe_response
rails latest stable - Class:
Dispatcher
Method deprecated or moved
This method is deprecated or moved on the latest stable version. The last existing version (v1.2.6) is shown here.
failsafe_response(output, status, exception = nil)private
If the block raises, send status code as a last-ditch response.
# File railties/lib/dispatcher.rb, line 135
def failsafe_response(output, status, exception = nil)
yield
rescue Exception # errors from executed block
begin
output.write "Status: #{status}\r\n"
if exception
message = exception.to_s + "\r\n" + exception.backtrace.join("\r\n")
error_path = File.join(RAILS_ROOT, 'public', '500.html')
if defined?(RAILS_DEFAULT_LOGGER) && !RAILS_DEFAULT_LOGGER.nil?
RAILS_DEFAULT_LOGGER.fatal(message)
output.write "Content-Type: text/html\r\n\r\n"
if File.exists?(error_path)
output.write(IO.read(error_path))
else
output.write("<html><body><h1>Application error (Rails)</h1></body></html>")
end
else
output.write "Content-Type: text/plain\r\n\r\n"
output.write(message)
end
end
rescue Exception # Logger or IO errors
end
end Related methods
- Class methods
- dispatch
- reset_application!
- to_prepare
- Private methods
-
failsafe_response -
new_cgi -
prepare_application -
prepare_breakpoint -
reset_after_dispatch -
run_preparation_callbacks