Class | Rack::ShowStatus |
In: |
lib/rack/showstatus.rb
|
Parent: | Object |
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 14: def initialize(app) 15: @app = app 16: @template = ERB.new(TEMPLATE) 17: end
# File lib/rack/showstatus.rb, line 19 19: def call(env) 20: status, headers, body = @app.call(env) 21: 22: # client or server error, or explicit message 23: if status.to_i >= 400 && 24: (body.empty? rescue false) || env["rack.showstatus.detail"] 25: req = Rack::Request.new(env) 26: message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s 27: detail = env["rack.showstatus.detail"] || message 28: [status, headers.merge("Content-Type" => "text/html"), [@template.result(binding)]] 29: else 30: [status, headers, body] 31: end 32: end