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.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/mbeditor/engine.rb', line 172 def self.subscribe_to_exceptions return if @exception_subscriber @exception_subscriber = ActiveSupport::Notifications.subscribe( "process_action.action_controller" ) do |_name, _started, _finished, _id, payload| # 5-arity: the block runs for every host request, and building an Event # just to read its payload allocated one per request for nothing. 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 |