Skip to content

Commit

Permalink
keep show_exception from displaying errors in the log. dump_errors is…
Browse files Browse the repository at this point in the history
… responsible for that.
  • Loading branch information
rkh committed Feb 19, 2011
1 parent 4d520c6 commit 45e79fc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/sinatra/showexceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,36 @@ module Sinatra
# Be careful when you use this on public-facing sites as it could reveal
# information helpful to attackers.
class ShowExceptions < Rack::ShowExceptions
@@eats_errors = Object.new
def @@eats_errors.flush(*) end
def @@eats_errors.puts(*) end

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

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

if respond_to?(:prefers_plain_text?) and 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" => Rack::Utils.bytesize(body.join).to_s},
body]
end

private

def frame_class(frame)
Expand Down

0 comments on commit 45e79fc

Please sign in to comment.