Class: Spar::Exceptions

Inherits:
Rack::ShowExceptions
  • Object
show all
Defined in:
lib/spar/exceptions.rb

Constant Summary collapse

@@eats_errors =
Object.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Exceptions

Returns a new instance of Exceptions.



10
11
12
13
# File 'lib/spar/exceptions.rb', line 10

def initialize(app)
  @app      = app
  @template = ERB.new(TEMPLATE)
end

Class Method Details

.flushObject



7
# File 'lib/spar/exceptions.rb', line 7

def @@eats_errors.flush(*) end

.putsObject



8
# File 'lib/spar/exceptions.rb', line 8

def @@eats_errors.puts(*) end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/spar/exceptions.rb', line 15

def call(env)
  @app.call(env)
rescue Exception => e
  errors, env["rack.errors"] = env["rack.errors"], @@eats_errors

  content_type = "text/html"
  body = pretty(env, e)

  env["rack.errors"] = errors

  [500,
   {"Content-Type" => content_type,
    "Content-Length" => Rack::Utils.bytesize(body.join).to_s},
   body]
end