Sha256: b70d74b71fe07915fe29cde7970be33ace44fdbcf77456e3884f833e04b2c939

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

module Sentry
  module Rails
    class RescuedExceptionInterceptor
      def initialize(app)
        @app = app
      end

      def call(env)
        return @app.call(env) unless Sentry.initialized?

        begin
          @app.call(env)
        rescue => e
          request = ActionDispatch::Request.new(env)

          # Rails' ShowExceptions#render_exception will mutate env for the exceptions app
          # so we need to hold a copy of env to report the accurate data (like request's url)
          if request.show_exceptions?
            scope = Sentry.get_current_scope
            copied_env = scope.rack_env.dup
            copied_env["sentry.original_transaction"] = scope.transaction_name
            scope.set_rack_env(copied_env)

            if report_rescued_exceptions?
              Sentry::Rails.capture_exception(e)
              env["sentry.already_captured"] = true
            end
          end

          env["sentry.rescued_exception"] = e if report_rescued_exceptions?
          raise e
        end
      end

      def report_rescued_exceptions?
        Sentry.configuration.rails.report_rescued_exceptions
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
sentry-rails-4.7.3 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.7.2 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.7.1 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.7.0 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.6.5 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.6.4 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.6.3 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.6.2 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.6.1 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.6.0 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.6.0.pre.beta.0 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.5.2 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.5.1 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.5.0 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.5.0.pre.beta.1 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.4.0 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-4.4.0.pre.beta.0 lib/sentry/rails/rescued_exception_interceptor.rb