Class: Cyberweb::REST::ShowExceptions

Inherits:
Rack::ShowExceptions
  • Object
show all
Defined in:
lib/cyberweb/REST/show_exceptions.rb

Overview

#

REST::ShowExceptions catches all exceptions raised from the app it wraps. It shows a useful backtrace with the sourcefile and clickable context, the whole Rack environment and the request data.

Be careful when you use this on public-facing sites as it could reveal information helpful to attackers.

#

Constant Summary collapse

@@eats_errors =
Object.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i) ⇒ ShowExceptions

#

initialize

#


30
31
32
# File 'lib/cyberweb/REST/show_exceptions.rb', line 30

def initialize(i)
  @app = i
end

Class Method Details

.flushObject



24
# File 'lib/cyberweb/REST/show_exceptions.rb', line 24

def @@eats_errors.flush(*) end

.putsObject



25
# File 'lib/cyberweb/REST/show_exceptions.rb', line 25

def @@eats_errors.puts(*) end

Instance Method Details

#call(env) ⇒ Object

#

call

#


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cyberweb/REST/show_exceptions.rb', line 37

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

  if prefers_plain_text?(env)
    content_type = 'text/plain'
    body = dump_exception(e)
  else
    content_type = 'text/html'
    body = pretty(env, e)
  end

  env['rack.errors'] = errors
  [
    500,
    {
      'Content-Type' => content_type,
      'Content-Length' => body.bytesize.to_s
    },
    [body]
  ]
end

#templateObject

#

template

#


65
66
67
# File 'lib/cyberweb/REST/show_exceptions.rb', line 65

def template
  TEMPLATE
end