Class: CrashdeskRack::Rack

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



3
4
5
# File 'lib/crashdesk-rack/rack.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/crashdesk-rack/rack.rb', line 7

def call(env)
  begin
    status, headers, body = @app.call(env)
  rescue Exception => exception
    $stdout.puts "Crashdesk rack rescue: #{exception.message}"

    request = ::Rack::Request.new(env)
    context = RackContext.new(env, request)

    begin
      crashlog = Crashdesk.crashlog(exception, request, context)
      crashlog.report

      env['crashdesk.crashlog_crc'] = crashlog.crc
    rescue Exception => e
      $stderr.puts "Crashdesk can has a bug: #{e.message}"
      $stderr.puts "Backtrace: ", e.backtrace
    end

    raise
  end

  [status, headers, body]
end