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.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/mbeditor/engine.rb', line 154 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 |