Sha256: 2cb4f07574e0d2dec5dff648bc78e59d497c8161204d591a90de7e10d18214d4

Contents?: true

Size: 996 Bytes

Versions: 3

Compression:

Stored size: 996 Bytes

Contents

module Raven
  # Middleware for Rack applications. Any errors raised by the upstream
  # application will be delivered to Sentry and re-raised.
  #
  # Synopsis:
  #
  #   require 'rack'
  #   require 'raven'
  #
  #   Raven.configure do |config|
  #     config.server = 'http://my_dsn'
  #   end
  #
  #   app = Rack::Builder.app do
  #     use Raven::Rack
  #     run lambda { |env| raise "Rack down" }
  #   end
  #
  # Use a standard Raven.configure call to configure your server credentials.
  class Rack
    def initialize(app)
      @app = app
    end

    def call(env)
      begin
        response = @app.call(env)
      rescue Error => e
        raise # Don't capture Raven errors
      rescue Exception => e
        evt = Event.capture_rack_exception(e, env)
        Raven.send(evt)
        raise
      end

      if env['rack.exception']
        evt = Event.capture_rack_exception(env['rack.exception'], env)
        Raven.send(evt) if evt
      end

      response
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sentry-raven-0.4.0 lib/raven/rack.rb
sentry-raven-0.3.1 lib/raven/rack.rb
sentry-raven-0.3 lib/raven/rack.rb