Class: GLExceptionNotifier
- Inherits:
-
Object
- Object
- GLExceptionNotifier
- Defined in:
- lib/gl_exception_notifier.rb
Constant Summary collapse
- CONTEXT_TYPES =
%i[extra_context tags_context user_context].freeze
Class Method Summary collapse
- .add_context(type, context) ⇒ Object
- .breadcrumbs(data:, message: nil) ⇒ Object
- .call(*args) ⇒ Object
- .capture_exception(args) ⇒ Object
- .capture_message(args) ⇒ Object
- .exceptionable?(obj) ⇒ Boolean
- .last_breadcrumb ⇒ Object
Class Method Details
.add_context(type, context) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gl_exception_notifier.rb', line 43 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.(context) when :extra_context error_client.set_extras(context) end end |
.breadcrumbs(data:, message: nil) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/gl_exception_notifier.rb', line 62 def (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 && !.is_a?(String) crumb = .new(message:, data:) error_client.(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 (args) end end |
.capture_exception(args) ⇒ Object
15 16 17 |
# File 'lib/gl_exception_notifier.rb', line 15 def capture_exception(args) error_client.capture_exception(*args) end |
.capture_message(args) ⇒ Object
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 (args) if args.first.is_a?(String) = args.first extra = args.length == 2 && args.last.is_a?(Hash) ? args.last : { parameters: args.drop(1) } else = if args.first.is_a?(Hash) 'called with kwargs, should have been positional' else 'Unknown parameter set' end = "GLExceptionNotifier: #{}" extra = { parameters: args } end error_client.(, extra:) end |
.exceptionable?(obj) ⇒ Boolean
36 37 38 39 |
# File 'lib/gl_exception_notifier.rb', line 36 def exceptionable?(obj) obj.is_a?(Exception) || (obj.respond_to?(:ancestors) && obj.ancestors.include?(Exception)) end |
.last_breadcrumb ⇒ Object
71 72 73 |
# File 'lib/gl_exception_notifier.rb', line 71 def error_client.get_current_scope&.&.peek end |