Class | Sinatra::ShowExceptions |
In: |
lib/sinatra/showexceptions.rb
|
Parent: | Rack::ShowExceptions |
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.
# File lib/sinatra/showexceptions.rb, line 15 15: def initializeinitializeinitialize(app) 16: @app = app 17: @template = ERB.new(TEMPLATE) 18: end
# File lib/sinatra/showexceptions.rb, line 20 20: def call(env) 21: @app.call(env) 22: rescue Exception => e 23: errors, env["rack.errors"] = env["rack.errors"], @@eats_errors 24: 25: if respond_to?(:prefers_plain_text?) and prefers_plain_text?(env) 26: content_type = "text/plain" 27: body = [dump_exception(e)] 28: else 29: content_type = "text/html" 30: body = pretty(env, e) 31: end 32: 33: env["rack.errors"] = errors 34: 35: [500, 36: {"Content-Type" => content_type, 37: "Content-Length" => Rack::Utils.bytesize(body.join).to_s}, 38: body] 39: end