Class: RailsErrorDashboard::ManualErrorReporter

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

Overview

ManualErrorReporter: Report errors manually from frontend, mobile apps, or custom sources

This class provides a clean API for logging errors that don’t originate from Ruby exceptions, such as JavaScript errors from the frontend, mobile app crashes, or manually constructed errors.

Examples:

Frontend JavaScript error

RailsErrorDashboard::ManualErrorReporter.report(
  error_type: "TypeError",
  message: "Cannot read property 'foo' of undefined",
  backtrace: ["at handleClick (app.js:42)", "at onClick (button.js:15)"],
  platform: "Web",
  user_id: current_user&.id,
  request_url: request.url,
  user_agent: request.user_agent,
  metadata: { component: "ShoppingCart", action: "checkout" }
)

Mobile app crash

RailsErrorDashboard::ManualErrorReporter.report(
  error_type: "NSException",
  message: "Fatal crash in payment processing",
  backtrace: stacktrace_array,
  platform: "iOS",
  app_version: "2.1.0",
  user_id: user_id,
  metadata: { device: "iPhone 14", os_version: "17.2" }
)

Defined Under Namespace

Modules: ManualErrors Classes: SyntheticException

Class Method Summary collapse

Class Method Details

.report(error_type:, message:, backtrace: nil, platform: nil, user_id: nil, request_url: nil, user_agent: nil, ip_address: nil, app_version: nil, metadata: nil, occurred_at: nil, severity: nil, source: nil) ⇒ ErrorLog?

Report a manual error to the dashboard

Examples:

Basic usage

ManualErrorReporter.report(
  error_type: "ValidationError",
  message: "Email format is invalid",
  platform: "Web"
)

With full context

ManualErrorReporter.report(
  error_type: "PaymentError",
  message: "Credit card declined",
  backtrace: ["checkout.js:123", "payment.js:45"],
  platform: "Web",
  user_id: current_user.id,
  request_url: checkout_url,
  user_agent: request.user_agent,
  ip_address: request.remote_ip,
  app_version: "1.2.3",
  metadata: { card_type: "visa", amount: 99.99 },
  severity: :high
)

Parameters:

  • error_type (String)

    The error class/type (e.g., “TypeError”, “NetworkError”)

  • message (String)

    The error message

  • backtrace (Array<String>, String, nil) (defaults to: nil)

    Stack trace as array of strings or newline-separated string

  • platform (String, nil) (defaults to: nil)

    Platform where error occurred (“Web”, “iOS”, “Android”, “API”)

  • user_id (String, Integer, nil) (defaults to: nil)

    ID of the user who experienced the error

  • request_url (String, nil) (defaults to: nil)

    URL where the error occurred

  • user_agent (String, nil) (defaults to: nil)

    User agent string

  • ip_address (String, nil) (defaults to: nil)

    IP address of the requester

  • app_version (String, nil) (defaults to: nil)

    Version of the app where error occurred

  • metadata (Hash, nil) (defaults to: nil)

    Additional custom metadata about the error

  • occurred_at (Time, nil) (defaults to: nil)

    When the error occurred (defaults to Time.current)

  • severity (Symbol, nil) (defaults to: nil)

    Severity level (:critical, :high, :medium, :low)

  • source (String, nil) (defaults to: nil)

    Source identifier (e.g., “frontend”, “mobile_app”)

Returns:

  • (ErrorLog, nil)

    The created error log record, or nil if filtered/ignored



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rails_error_dashboard/manual_error_reporter.rb', line 71

def self.report(
  error_type:,
  message:,
  backtrace: nil,
  platform: nil,
  user_id: nil,
  request_url: nil,
  user_agent: nil,
  ip_address: nil,
  app_version: nil,
  metadata: nil,
  occurred_at: nil,
  severity: nil,
  source: nil
)
  # Create a synthetic exception object that quacks like a Ruby exception
  synthetic_exception = SyntheticException.new(
    error_type: error_type,
    message: message,
    backtrace: normalize_backtrace(backtrace)
  )

  # Build context hash for LogError
  context = {
    source: source || "manual",
    user_id: user_id,
    request_url: request_url,
    user_agent: user_agent,
    ip_address: ip_address,
    platform: platform,
    app_version: app_version,
    metadata: ,
    occurred_at: occurred_at || Time.current,
    severity: severity
  }.compact # Remove nil values

  # Use the existing LogError command
  Commands::LogError.call(synthetic_exception, context)
end