Rails 2.3.3.1
Update to latest Rails. A little bit of jiggery-pokery is involved, since they neglected to re-include vendored Rack in this release.
This commit is contained in:
parent
329fafafce
commit
664552ac02
257 changed files with 4346 additions and 1682 deletions
|
@ -1,4 +1,19 @@
|
|||
require 'erb'
|
||||
|
||||
module ActionController
|
||||
# The Failsafe middleware is usually the top-most middleware in the Rack
|
||||
# middleware chain. It returns the underlying middleware's response, but if
|
||||
# the underlying middle raises an exception then Failsafe will log the
|
||||
# exception into the Rails log file, and will attempt to return an error
|
||||
# message response.
|
||||
#
|
||||
# Failsafe is a last resort for logging errors and for telling the HTTP
|
||||
# client that something went wrong. Do not confuse this with the
|
||||
# ActionController::Rescue module, which is responsible for catching
|
||||
# exceptions at deeper levels. Unlike Failsafe, which is as simple as
|
||||
# possible, Rescue provides features that allow developers to hook into
|
||||
# the error handling logic, and can customize the error message response
|
||||
# based on the HTTP client's IP.
|
||||
class Failsafe
|
||||
cattr_accessor :error_file_path
|
||||
self.error_file_path = Rails.public_path if defined?(Rails.public_path)
|
||||
|
@ -11,7 +26,7 @@ module ActionController
|
|||
@app.call(env)
|
||||
rescue Exception => exception
|
||||
# Reraise exception in test environment
|
||||
if env["rack.test"]
|
||||
if defined?(Rails) && Rails.env.test?
|
||||
raise exception
|
||||
else
|
||||
failsafe_response(exception)
|
||||
|
@ -21,18 +36,37 @@ module ActionController
|
|||
private
|
||||
def failsafe_response(exception)
|
||||
log_failsafe_exception(exception)
|
||||
[500, {'Content-Type' => 'text/html'}, failsafe_response_body]
|
||||
[500, {'Content-Type' => 'text/html'}, [failsafe_response_body]]
|
||||
rescue Exception => failsafe_error # Logger or IO errors
|
||||
$stderr.puts "Error during failsafe response: #{failsafe_error}"
|
||||
end
|
||||
|
||||
def failsafe_response_body
|
||||
error_path = "#{self.class.error_file_path}/500.html"
|
||||
if File.exist?(error_path)
|
||||
File.read(error_path)
|
||||
error_template_path = "#{self.class.error_file_path}/500.html"
|
||||
if File.exist?(error_template_path)
|
||||
begin
|
||||
result = render_template(error_template_path)
|
||||
rescue Exception
|
||||
result = nil
|
||||
end
|
||||
else
|
||||
"<html><body><h1>500 Internal Server Error</h1></body></html>"
|
||||
result = nil
|
||||
end
|
||||
if result.nil?
|
||||
result = "<html><body><h1>500 Internal Server Error</h1>" <<
|
||||
"If you are the administrator of this website, then please read this web " <<
|
||||
"application's log file to find out what went wrong.</body></html>"
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# The default 500.html uses the h() method.
|
||||
def h(text) # :nodoc:
|
||||
ERB::Util.h(text)
|
||||
end
|
||||
|
||||
def render_template(filename)
|
||||
ERB.new(File.read(filename)).result(binding)
|
||||
end
|
||||
|
||||
def log_failsafe_exception(exception)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue