class Deas::ShowExceptions

Public Class Methods

new(app) click to toggle source
# File lib/deas/show_exceptions.rb, line 7
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source

The Rack call interface. The receiver acts as a prototype and runs each request in a clone object unless the rack.run_once variable is set in the environment. Ripped from: github.com/rtomayko/rack-cache/blob/master/lib/rack/cache/context.rb

# File lib/deas/show_exceptions.rb, line 15
def call(env)
  if env['rack.run_once']
    call! env
  else
    clone.call! env
  end
end
call!(env) click to toggle source

The real Rack call interface.

# File lib/deas/show_exceptions.rb, line 24
def call!(env)
  status, headers, body = @app.call(env)
  if error = env['deas.error']
    error_body = Body.new(error)

    headers['Content-Length'] = error_body.size.to_s
    headers['Content-Type']   = error_body.mime_type.to_s
    body = [error_body.content]
  end
  [status, headers, body]
end