lib/stealth/controller/catch_all.rb in stealth-1.1.6 vs lib/stealth/controller/catch_all.rb in stealth-2.0.0.beta1

- old
+ new

@@ -7,21 +7,44 @@ extend ActiveSupport::Concern included do - def run_catch_all(reason: nil) + def run_catch_all(err:) error_level = fetch_error_level - Stealth::Logger.l(topic: "catch_all", message: "CatchAll #{calculate_catch_all_state(error_level)} triggered for #{error_slug}: #{reason}") + if err.class == Stealth::Errors::UnrecognizedMessage + Stealth::Logger.l( + topic: 'catch_all', + message: "[Level #{error_level}] for user #{current_session_id} #{err.message}" + ) + else + Stealth::Logger.l( + topic: 'catch_all', + message: "[Level #{error_level}] for user #{current_session_id} #{[err.class, err.message, err.backtrace.join("\n")].join("\n")}" + ) + end + + # Store the reason so it can be accessed by the CatchAllsController + current_message.catch_all_reason = { + err: err.class, + err_msg: err.message + } + + # Don't run catch_all from the catch_all controller + if current_session.flow_string == 'catch_all' + Stealth::Logger.l(topic: 'catch_all', message: "CatchAll triggered for user #{current_session_id} from within CatchAll; ignoring.") + return false + end + if defined?(CatchAllsController) && FlowMap.flow_spec[:catch_all].present? catch_all_state = calculate_catch_all_state(error_level) if FlowMap.flow_spec[:catch_all].states.keys.include?(catch_all_state.to_sym) - step_to flow: 'catch_all', state: catch_all_state + step_to flow: :catch_all, state: catch_all_state else # We are out of bounds, do nothing to prevent an infinite loop - Stealth::Logger.l(topic: "catch_all", message: "Stopping; we've exceeded the number of defined catch_all states.") + Stealth::Logger.l(topic: 'catch_all', message: "Stopping; we\'ve exceeded the number of defined catch_all states for user #{current_session_id}.") return false end end end