Class: ExceptionHunter::ErrorCreator

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

Overview

Core class in charge of the actual persistence of errors and notifications.

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) ⇒ ExceptionHunter::Error, false

Creates an error with the given attributes and persists it to the database.

Parameters:

Returns:



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

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

  ActiveRecord::Base.transaction do
    error_attrs = extract_user_data(error_attrs)
    error_attrs = hide_sensitive_values(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!
    return if error_group.ignored?

    notify(error)
    error
  end
rescue ActiveRecord::RecordInvalid
  false
end