Module: ExceptionHunter::Tracking

Included in:
ExceptionHunter
Defined in:
lib/exception_hunter/tracking.rb

Overview

Mixin used to track manual exceptions.

Instance Method Summary collapse

Instance Method Details

#track(exception, custom_data: {}, user: nil) ⇒ void

This method returns an undefined value.

Used to manually track errors in cases where raising might not be adequate and but some insight is desired.

Examples:

Track the else clause on a case

case user.status
when :active then do_something()
when :inactive then do_something_else()
else
  ExceptionHunter.track(StandardError.new("User with unknown status"),
                                          custom_data: { status: user.status },
                                          user: user)
end

Parameters:

  • exception (Exception)

    to track.

  • custom_data (Hash) (defaults to: {})

    to include and help debug the error. (optional)

  • user (User) (defaults to: nil)

    in the current session. (optional)



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/exception_hunter/tracking.rb', line 21

def track(exception, custom_data: {}, user: nil)
  ErrorCreator.call(
    tag: ErrorCreator::MANUAL_TAG,
    class_name: exception.class.to_s,
    message: exception.message,
    backtrace: exception.backtrace,
    custom_data: custom_data,
    user: user,
    environment_data: {}
  )

  nil
end