Sha256: e6a6ac0c90e42a41c4a6963f2e4a8ec33ab15c7695ae1521b9338f86aa6a0a78

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 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
            scope.set_rack_env(scope.rack_env.dup)
            transaction = scope.transaction_name

            # we also need to make sure the transaction name won't be overridden by the exceptions app
            scope.add_event_processor do |event, hint|
              event.transaction = transaction
              event
            end
          end

          env["sentry.rescued_exception"] = e if Sentry.configuration.rails.report_rescued_exceptions
          raise e
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sentry-rails-4.1.6 lib/sentry/rails/rescued_exception_interceptor.rb