Class: RailsErrorDashboard::Middleware::ErrorCatcher
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Middleware::ErrorCatcher
- Defined in:
- lib/rails_error_dashboard/middleware/error_catcher.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ErrorCatcher
constructor
A new instance of ErrorCatcher.
Constructor Details
#initialize(app) ⇒ ErrorCatcher
Returns a new instance of ErrorCatcher.
18 19 20 |
# File 'lib/rails_error_dashboard/middleware/error_catcher.rb', line 18 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rails_error_dashboard/middleware/error_catcher.rb', line 22 def call(env) @app.call(env) rescue => exception # Report to Rails.error (will be logged by our ErrorReporter) # CRITICAL: Wrap in rescue to ensure gem failures don't break the app begin Rails.error.report(exception, handled: false, severity: :error, context: { request: ActionDispatch::Request.new(env), middleware: true }, source: "rack.middleware" ) rescue => e # If error reporting fails, log it but DON'T break the app RailsErrorDashboard::Logger.error("[RailsErrorDashboard] Middleware error reporting failed: #{e.class} - #{e.}") RailsErrorDashboard::Logger.error(e.backtrace&.first(5)&.join("\n")) if e.backtrace end # Re-raise original exception to let Rails handle the response raise exception end |