Sha256: 02a53b5836f953338b353e11dcc26067ac8a70faefd4855cb5f6eb0873cda7ae

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

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
          env["sentry.rescued_exception"] = e if report_rescued_exceptions?
          raise e
        end
      end

      def report_rescued_exceptions?
        # In rare edge cases, `Sentry.configuration` might be `nil` here.
        # Hence, we use a safe navigation and fallback to a reasonable default
        # of `true` in case the configuration couldn't be loaded.
        # See https://github.com/getsentry/sentry-ruby/issues/2386
        report_rescued_exceptions = Sentry.configuration&.rails&.report_rescued_exceptions
        return report_rescued_exceptions unless report_rescued_exceptions.nil?

        # `true` is the default for `report_rescued_exceptions`, as specified in
        # `sentry-rails/lib/sentry/rails/configuration.rb`.
        true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sentry-rails-5.22.2 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-5.22.1 lib/sentry/rails/rescued_exception_interceptor.rb
sentry-rails-5.22.0 lib/sentry/rails/rescued_exception_interceptor.rb