Sha256: 6f5e2d0f43176e30c39fbe1e55da3ae5b41a8f07be11c4a94c6935503992ab3a

Contents?: true

Size: 1.04 KB

Versions: 1

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
        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

1 entries across 1 versions & 1 rubygems

Version Path
sentry-raven-0.4.5 lib/raven/rack.rb