class Sentry::Rails::RescuedExceptionInterceptor

Public Class Methods

new(app) click to toggle source
# File lib/sentry/rails/rescued_exception_interceptor.rb, line 4
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/sentry/rails/rescued_exception_interceptor.rb, line 8
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
report_rescued_exceptions?() click to toggle source
# File lib/sentry/rails/rescued_exception_interceptor.rb, line 35
def report_rescued_exceptions?
  Sentry.configuration.rails.report_rescued_exceptions
end