Class: RailsErrorDashboard::ErrorReporter

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

Instance Method Summary collapse

Instance Method Details

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_error_dashboard/error_reporter.rb', line 21

def report(error, handled:, severity:, context:, source: nil)
  # Skip low-severity warnings
  return if handled && severity == :warning

  # CRITICAL: Wrap entire process in rescue to ensure failures don't break the app
  begin
    # Extract context information
    error_context = ValueObjects::ErrorContext.new(context, source)

    # Log to our error dashboard using Command
    Commands::LogError.call(error, error_context.to_h.merge(source: source))
  rescue => e
    # Don't let error logging cause more errors - fail silently
    # Log failure for debugging but NEVER propagate exception
    RailsErrorDashboard::Logger.error("[RailsErrorDashboard] ErrorReporter failed: #{e.class} - #{e.message}")
    RailsErrorDashboard::Logger.error("Original error: #{error.class} - #{error.message}") if error
    RailsErrorDashboard::Logger.error("Context: #{context.inspect}") if context
    RailsErrorDashboard::Logger.error(e.backtrace&.first(5)&.join("\n")) if e.backtrace
    nil # Explicitly return nil, never raise
  end
end