Class: Sentry::Rails::RescuedExceptionInterceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/rails/rescued_exception_interceptor.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RescuedExceptionInterceptor

Returns a new instance of RescuedExceptionInterceptor.



6
7
8
# File 'lib/sentry/rails/rescued_exception_interceptor.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/sentry/rails/rescued_exception_interceptor.rb', line 10

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

#report_rescued_exceptions?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sentry/rails/rescued_exception_interceptor.rb', line 21

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