Class: ExceptionHunter::ErrorCreator

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

Constant Summary collapse

HTTP_TAG =
'HTTP'.freeze
WORKER_TAG =
'Worker'.freeze
MANUAL_TAG =
'Manual'.freeze

Class Method Summary collapse

Class Method Details

.call(tag: nil, **error_attrs) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/exception_hunter/error_creator.rb', line 8

def call(tag: nil, **error_attrs)
  return unless should_create?

  ActiveRecord::Base.transaction do
    error_attrs = extract_user_data(error_attrs)
    error = ::ExceptionHunter::Error.new(error_attrs)
    error_group = ::ExceptionHunter::ErrorGroup.find_matching_group(error) || ::ExceptionHunter::ErrorGroup.new
    update_error_group(error_group, error, tag)
    error.error_group = error_group
    error.save!
    error
  end
rescue ActiveRecord::RecordInvalid
  false
end