diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-14 21:28:37 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-14 21:28:37 -0300 |
commit | 9611d561edc9f816b9bf035730d6aa68b0356ab5 (patch) | |
tree | e02a70f8e97a1742a308b34e301808a7f26ed404 | |
parent | 46a2917deda5207ff208ac03b85c7ae8396c8501 (diff) | |
download | rails-9611d561edc9f816b9bf035730d6aa68b0356ab5.tar.gz rails-9611d561edc9f816b9bf035730d6aa68b0356ab5.tar.bz2 rails-9611d561edc9f816b9bf035730d6aa68b0356ab5.zip |
Refactor public exceptions to reuse render format method
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/public_exceptions.rb | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/public_exceptions.rb b/actionpack/lib/action_dispatch/middleware/public_exceptions.rb index 204f3f7fb3..633604c423 100644 --- a/actionpack/lib/action_dispatch/middleware/public_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/public_exceptions.rb @@ -15,23 +15,21 @@ module ActionDispatch format = content_type && "to_#{content_type.to_sym}" body = { :status => status, :error => exception.message } - render(status, body, :format => format, :content_type => content_type) + render(status, body, format, content_type) end private - def render(status, body, options) - format = options[:format] - + def render(status, body, format, content_type) if format && body.respond_to?(format) - render_format(status, body.public_send(format), options) + render_format(status, content_type, body.public_send(format)) else render_html(status) end end - def render_format(status, body, options) - [status, {'Content-Type' => "#{options[:content_type]}; charset=#{ActionDispatch::Response.default_charset}", + def render_format(status, content_type, body) + [status, {'Content-Type' => "#{content_type}; charset=#{ActionDispatch::Response.default_charset}", 'Content-Length' => body.bytesize.to_s}, [body]] end @@ -41,8 +39,7 @@ module ActionDispatch path = "#{public_path}/#{status}.html" unless path && (found = File.exist?(path)) if found || File.exist?(path) - body = File.read(path) - [status, {'Content-Type' => "text/html; charset=#{Response.default_charset}", 'Content-Length' => body.bytesize.to_s}, [body]] + render_format(status, 'text/html', File.read(path)) else [404, { "X-Cascade" => "pass" }, []] end |