Skip to content
Permalink
Browse files

ShowExceptions minor refactoring

* Load HTML exception template only if needed
* Only #call is public
* Enumerable body concern in one place
  • Loading branch information...
bestie authored and raggi committed Aug 10, 2013
1 parent 2ab24cf commit 893a2c505a3a43b4f224b50ea06567dacb473cae
Showing with 12 additions and 7 deletions.
  1. +12 −7 lib/rack/showexceptions.rb
@@ -17,7 +17,6 @@ class ShowExceptions

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

def call(env)
@@ -33,15 +32,21 @@ def call(env)
body = pretty(env, e)
else
content_type = "text/plain"
body = [exception_string]
body = exception_string
end

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

private

def accepts_html?(env)
env["HTTP_ACCEPT"] && env["HTTP_ACCEPT"].include?("text/html")
end
@@ -85,7 +90,7 @@ def pretty(env, exception)
end
}.compact

[@template.result(binding)]
ERB.new(TEMPLATE).result(binding)
end

def h(obj) # :nodoc:

2 comments on commit 893a2c5

@vipulnsward

This comment has been minimized.

Copy link
Contributor

replied Jul 22, 2014

The change in return type causes sinatra/sinatra#906 . Is this method public?

@raggi

This comment has been minimized.

Copy link
Member

replied Jul 22, 2014

No, the method is not public.

Please sign in to comment.
You can’t perform that action at this time.