Class: Brochure::Failsafe

Inherits:
Object
  • Object
show all
Defined in:
lib/brochure/failsafe.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Failsafe

Returns a new instance of Failsafe.



3
4
5
# File 'lib/brochure/failsafe.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/brochure/failsafe.rb', line 7

def call(env)
  @app.call(env)
rescue Exception => exception
  backtrace = ["#{exception.class.name}: #{exception}", *exception.backtrace].join("\n  ")
  env["rack.errors"].puts(backtrace)
  env["rack.errors"].flush

  body = <<-HTML
    <!DOCTYPE html>
    <html><head><title>Internal Server Error</title></head>
    <body><h1>500 Internal Server Error</h1></body></html>
  HTML

  [500,
   { "Content-Type"   => "text/html, charset=utf-8",
     "Content-Length" => Rack::Utils.bytesize(body).to_s },
   [body]]
end