Class: NeverForget::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/never_forget/exception_handler.rb

Constant Summary collapse

TEMPLATE_FILE =
File.expand_path('../list_exceptions.erb', __FILE__)

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



9
10
11
12
# File 'lib/never_forget/exception_handler.rb', line 9

def initialize(app, options = {})
  @app = app
  @options = {:list_path => '/_exceptions'}.update(options)
end

Instance Method Details

#call(env) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/never_forget/exception_handler.rb', line 23

def call(env)
  if env['PATH_INFO'] == File.join('/', @options[:list_path])
    body = render_exceptions_view
    [200, {'content-type' => 'text/html'}, [body]]
  else
    forward(env)
  end
end

#exceptions_templateObject



39
40
41
# File 'lib/never_forget/exception_handler.rb', line 39

def exceptions_template
  File.read(TEMPLATE_FILE)
end

#forward(env) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/never_forget/exception_handler.rb', line 14

def forward(env)
  begin
    @app.call(env)
  rescue StandardError, ScriptError => error
    NeverForget.log(error, env)
    raise error
  end
end

#render_exceptions_viewObject



32
33
34
35
36
37
# File 'lib/never_forget/exception_handler.rb', line 32

def render_exceptions_view
  template = Erubis::Eruby.new(exceptions_template)
  context = Erubis::Context.new(:recent => Exception.recent)
  context.extend TemplateHelpers
  template.evaluate(context)
end