Class: Xhummingbird::Rack::CaptureException

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

Constant Summary collapse

CONVERT_KEYS =
Set.new(%w(
  REQUEST_METHOD
  SCRIPT_NAME
  PATH_INFO
  QUERY_STRING
  SERVER_NAME
  SERVER_PORT
  rack.version
  rack.url_scheme
  rack.multithread
  rack.multiprocess
  rack.run_once
  rack.hijack?
))
HTTP_HEADER_PREFIX =
'HTTP_'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CaptureException

Returns a new instance of CaptureException.



21
22
23
# File 'lib/xhummingbird/rack/capture_exception.rb', line 21

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/xhummingbird/rack/capture_exception.rb', line 25

def call(env)
  begin
    response = @app.call(env)
  rescue => e
    Xhummingbird.send_exception(e, tags: convert_to_rack_tags(env))
  end

  error = env['rack.exception'] || env['sinatra.error']

  if error
    level = (400..499).include?(response.first.to_i) ? 0 : 2

    Xhummingbird.send_exception(error, level: level, tags: convert_to_rack_tags(env))
  end

  response
end