Class: Sinatra::ShowExceptions
- Inherits:
-
Rack::ShowExceptions
- Object
- Rack::ShowExceptions
- Sinatra::ShowExceptions
- Defined in:
- lib/sinatra/show_exceptions.rb
Overview
Sinatra::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
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ShowExceptions
constructor
A new instance of ShowExceptions.
- #template ⇒ Object
Constructor Details
#initialize(app) ⇒ ShowExceptions
Returns a new instance of ShowExceptions.
18 19 20 |
# File 'lib/sinatra/show_exceptions.rb', line 18 def initialize(app) @app = app end |
Class Method Details
.flush ⇒ Object
14 |
# File 'lib/sinatra/show_exceptions.rb', line 14 def @@eats_errors.flush(*) end |
.puts ⇒ Object
16 |
# File 'lib/sinatra/show_exceptions.rb', line 16 def @@eats_errors.puts(*) end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sinatra/show_exceptions.rb', line 22 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 |
#template ⇒ Object
48 49 50 |
# File 'lib/sinatra/show_exceptions.rb', line 48 def template TEMPLATE end |