Sha256: ec94345d6b55255614790ad0ab4bd9d53d6831ee91d372c211044e5aaf339451

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

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
      ensure
        Raven.context.clear!
      end

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

      if error
        evt = Event.capture_rack_exception(error, 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.4 lib/raven/rack.rb
sentry-raven-0.4.3 lib/raven/rack.rb
sentry-raven-0.4.2 lib/raven/rack.rb