Class: ExceptionHub::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_hub/rack.rb

Overview

Rack middleware to intercept exceptions

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



4
5
6
# File 'lib/exception_hub/rack.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/exception_hub/rack.rb', line 12

def call(env)
  begin
    response = @app.call(env)
  rescue Exception => ex
    env['exception_hub.issue_id'] = handle_exception(ex, env)
    raise
  end

  if env['rack.exception']
    env['exception_hub.issue_id'] = handle_exception(ex, env)
  end

  response
end

#handle_exception(exception, env) ⇒ Object



8
9
10
# File 'lib/exception_hub/rack.rb', line 8

def handle_exception(exception, env)
  ExceptionHub.handle_exception(exception, env)
end