class ShowExceptions

Attributes

app[R]
error[R]

Public Class Methods

new(app) click to toggle source
# File lib/show_exceptions.rb, line 4
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/show_exceptions.rb, line 8
def call(env)
  begin
    @app.call(env)
  rescue StandardError => e
    render_exception(e)
  end
end

Private Instance Methods

render_exception(e) click to toggle source
# File lib/show_exceptions.rb, line 18
def render_exception(e)
  res = Rack::Response.new
  file_content = File.read("#{File.dirname(__FILE__)}/templates/rescue.html.erb")
  content = ERB.new(file_content).result(binding)

  res['Content-Type'] = 'text/html'
  res.status = 500
  res.write(content)
  res.finish
end