Class: Mbeditor::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- Mbeditor::Engine
- Defined in:
- lib/mbeditor/engine.rb
Class Method Summary collapse
-
.subscribe_to_exceptions ⇒ Object
Records controller exceptions into ExceptionLog and pushes them to any open editor over the existing cable channel.
Class Method Details
.subscribe_to_exceptions ⇒ Object
Records controller exceptions into ExceptionLog and pushes them to any open editor over the existing cable channel.
process_action.action_controller rather than a Rack middleware: ActionDispatch::DebugExceptions rescues and renders the error, so nothing outside it ever sees the raise. Rails.error.subscribe would be a cleaner API but only carries unhandled request errors reliably on newer Rails, and this gem supports 7.1.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/mbeditor/engine.rb', line 140 def self.subscribe_to_exceptions return if @exception_subscriber @exception_subscriber = ActiveSupport::Notifications.subscribe( "process_action.action_controller" ) do |*args| payload = ActiveSupport::Notifications::Event.new(*args).payload exception = payload[:exception_object] next unless exception entry = Mbeditor::ExceptionLog.record( exception, payload, workspace_root: Mbeditor::WorkspaceRootResolver.call ) next unless entry && defined?(ActionCable.server) ActionCable.server.broadcast("mbeditor_editor", entry) rescue StandardError => e # A monitoring hook must never be able to break the request it observes. Rails.logger.debug("[mbeditor] exception capture failed: #{e.class}: #{e.}") end end |