Sha256: ba99bdb38c9be72fd54dd6d68d6b6181d90c84441b9a53ad78c6e645cedd4a0c

Contents?: true

Size: 983 Bytes

Versions: 2

Compression:

Stored size: 983 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) if evt
        raise
      end

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

      response
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sentry-raven-0.2 lib/raven/rack.rb
sentry-raven-0.1 lib/raven/rack.rb