Class: RailsErrorDashboard::Services::SeverityClassifier

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/services/severity_classifier.rb

Overview

Pure algorithm: Classify error severity based on error type

No database access — accepts an error_type string, returns a severity symbol. Checks custom severity rules from configuration first, then falls back to built-in classification based on error type constants.

Constant Summary collapse

CRITICAL_ERROR_TYPES =
%w[
  SecurityError
  NoMemoryError
  SystemStackError
  SignalException
  ActiveRecord::StatementInvalid
  LoadError
  SyntaxError
  ActiveRecord::ConnectionNotEstablished
  Redis::ConnectionError
  OpenSSL::SSL::SSLError
].freeze
HIGH_SEVERITY_ERROR_TYPES =
%w[
  ActiveRecord::RecordNotFound
  ArgumentError
  TypeError
  NoMethodError
  NameError
  ZeroDivisionError
  FloatDomainError
  IndexError
  KeyError
  RangeError
].freeze
MEDIUM_SEVERITY_ERROR_TYPES =
%w[
  ActiveRecord::RecordInvalid
  Timeout::Error
  Net::ReadTimeout
  Net::OpenTimeout
  ActiveRecord::RecordNotUnique
  JSON::ParserError
  CSV::MalformedCSVError
  Errno::ECONNREFUSED
].freeze

Class Method Summary collapse

Class Method Details

.classify(error_type) ⇒ Symbol

Classify the severity of an error type

Parameters:

  • error_type (String)

    The error class name

Returns:

  • (Symbol)

    :critical, :high, :medium, or :low



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rails_error_dashboard/services/severity_classifier.rb', line 51

def self.classify(error_type)
  # Check custom severity rules first
  custom_severity = RailsErrorDashboard.configuration.custom_severity_rules[error_type]
  return custom_severity.to_sym if custom_severity.present?

  # Fall back to default classification
  return :critical if CRITICAL_ERROR_TYPES.include?(error_type)
  return :high if HIGH_SEVERITY_ERROR_TYPES.include?(error_type)
  return :medium if MEDIUM_SEVERITY_ERROR_TYPES.include?(error_type)

  :low
end

.critical?(error_type) ⇒ Boolean

Check if an error type is critical

Parameters:

  • error_type (String)

    The error class name

Returns:

  • (Boolean)


67
68
69
# File 'lib/rails_error_dashboard/services/severity_classifier.rb', line 67

def self.critical?(error_type)
  classify(error_type) == :critical
end