Class: SolidErrors::Subscriber

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

Constant Summary collapse

IGNORED_ERRORS =
["ActionController::RoutingError",
"AbstractController::ActionNotFound",
"ActionController::MethodNotAllowed",
"ActionController::UnknownHttpMethod",
"ActionController::NotImplemented",
"ActionController::UnknownFormat",
"ActionController::InvalidAuthenticityToken",
"ActionController::InvalidCrossOriginRequest",
"ActionDispatch::Http::Parameters::ParseError",
"ActionController::BadRequest",
"ActionController::ParameterMissing",
"ActiveRecord::RecordNotFound",
"ActionController::UnknownAction",
"ActionDispatch::Http::MimeNegotiation::InvalidType",
"Rack::QueryParser::ParameterTypeError",
"Rack::QueryParser::InvalidParameterError",
"CGI::Session::CookieStore::TamperedWithCookie",
"Mongoid::Errors::DocumentNotFound",
"Sinatra::NotFound",
"Sidekiq::JobRetry::Skip"].map(&:freeze).freeze

Instance Method Summary collapse

Instance Method Details

#ignore_by_class?(error_class_name) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/solid_errors/subscriber.rb', line 51

def ignore_by_class?(error_class_name)
  IGNORED_ERRORS.any? do |ignored_class|
    ignored_class_name = ignored_class.respond_to?(:name) ? ignored_class.name : ignored_class

    ignored_class_name == error_class_name
  end
end

#report(error, handled:, severity:, context:, source: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/solid_errors/subscriber.rb', line 24

def report(error, handled:, severity:, context:, source: nil)
  return if ignore_by_class?(error.class.name)

  error_attributes = {
    exception_class: error.class.name,
    message: s(error.message),
    severity: severity,
    source: source
  }
  fingerprint = Digest::SHA256.hexdigest(error_attributes.values.join)
  if (record = SolidErrors::Error.find_by(fingerprint: fingerprint))
    record.update!(resolved_at: nil, updated_at: Time.now)
  else
    record = SolidErrors::Error.create!(error_attributes.merge(fingerprint: fingerprint))
  end

  SolidErrors::Occurrence.create(
    error_id: record.id,
    backtrace: error.backtrace&.join("\n"),
    context: s(context)
  )
end

#s(data) ⇒ Object



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

def s(data)
  Sanitizer.sanitize(data)
end