Rack::ShowStatus catches all empty responses the app it wraps and replaces them with a site explaining the error.
Additional details can be put into rack.showstatus.detail
and
will be shown as HTML. If such details exist, the error page is always
rendered, even if the reply was not empty.
# File lib/rack/showstatus.rb, line 14 def initialize(app) @app = app @template = ERB.new(TEMPLATE) end
# File lib/rack/showstatus.rb, line 19 def call(env) status, headers, body = @app.call(env) headers = Utils::HeaderHash.new(headers) empty = headers['Content-Length'].to_i <= 0 # client or server error, or explicit message if (status.to_i >= 400 && empty) || env["rack.showstatus.detail"] req = Rack::Request.new(env) message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s detail = env["rack.showstatus.detail"] || message body = @template.result(binding) size = Rack::Utils.bytesize(body) [status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]] else [status, headers, body] end end