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)


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

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)


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

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



9
10
11
12
13
14
15
# File 'lib/gl_exception_notifier.rb', line 9

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

.last_breadcrumbObject



47
48
49
# File 'lib/gl_exception_notifier.rb', line 47

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