Class: GLExceptionNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/gl_exception_notifier.rb

Constant Summary collapse

CONTEXT_TYPES =
i[extra_context tags_context user_context].freeze

Class Method Summary collapse

Class Method Details

.add_context(type, context) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gl_exception_notifier.rb', line 17

def add_context(type, context)
  unless CONTEXT_TYPES.include?(type)
    raise ArgumentError,
          'type paramater must be one of: :extra_context, :tags_context, :user_context'
  end
  raise ArgumentError, 'contexts must be a hash' unless context.is_a?(Hash)

  case type
  when :user_context
    error_client.set_user(context)
  when :tags_context
    error_client.set_tags(context)
  when :extra_context
    error_client.set_extras(context)
  end
end

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
# File 'lib/gl_exception_notifier.rb', line 36

def breadcrumbs(data:, message: nil)
  raise ArgumentError, 'data must be a hash' unless data.is_a?(Hash)
  raise ArgumentError, 'when providing a message, it must be a string' if message && !message.is_a?(String)

  crumb = breadcrumb.new(message:, data:)
  error_client.add_breadcrumb(crumb)
  crumb
end

.call(*args) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/gl_exception_notifier.rb', line 7

def call(*args)
  if exceptionable?(args.first)
    capture_exception(args)
  else
    capture_message(args)
  end
end

.last_breadcrumbObject



45
46
47
# File 'lib/gl_exception_notifier.rb', line 45

def last_breadcrumb
  error_client.get_current_scope&.breadcrumbs&.peek
end