From 8d754b8074b6144a88e5ba87c1519c626c40247a Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Sun, 8 Oct 2023 11:03:09 +0300 Subject: [PATCH] fix breaking issues Rename named parameter, and change rescue error message --- app/channels/stimulus_reflex/channel.rb | 3 ++- lib/stimulus_reflex/reflex.rb | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/channels/stimulus_reflex/channel.rb b/app/channels/stimulus_reflex/channel.rb index 04c10c0f..949bea4c 100644 --- a/app/channels/stimulus_reflex/channel.rb +++ b/app/channels/stimulus_reflex/channel.rb @@ -16,13 +16,14 @@ def receive(data) delegate_call_to_reflex reflex rescue => exception error = exception_with_backtrace(exception) - error_message = "\e[31mReflex #{reflex.data.target} failed: #{error[:message]} [#{reflex.url}]\e[0m\n#{error[:stack]}" if reflex + error_message = "\e[31mReflex #{reflex.data.target} failed: #{error[:message]} [#{reflex.url}]\e[0m\n#{error[:stack]}" reflex.rescue_with_handler(exception) reflex.logger&.error error_message reflex.broadcast_error data: data, error: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}" else + error_message = "\e[31mReflex failed: #{error[:message]} \e[0m\n#{error[:stack]}" unless exception.is_a?(StimulusReflex::VersionMismatchError) StimulusReflex.config.logger.error error_message end diff --git a/lib/stimulus_reflex/reflex.rb b/lib/stimulus_reflex/reflex.rb index 445cb660..d9bdc411 100644 --- a/lib/stimulus_reflex/reflex.rb +++ b/lib/stimulus_reflex/reflex.rb @@ -12,21 +12,21 @@ class StimulusReflex::Reflex include CableReady::Identifiable attr_accessor :payload, :headers - attr_reader :channel, :reflex_data, :broadcaster + attr_reader :channel, :data, :broadcaster delegate :connection, :stream_name, to: :channel delegate :controller_class, :flash, :session, to: :request delegate :broadcast, :broadcast_halt, :broadcast_forbid, :broadcast_error, to: :broadcaster # TODO remove xpath_controller and xpath_element for v4 - delegate :url, :element, :selectors, :method_name, :id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :version, :npm_version, :suppress_logging, to: :reflex_data + delegate :url, :element, :selectors, :method_name, :id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :version, :npm_version, :suppress_logging, to: :data # END TODO: remove alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name - def initialize(channel, reflex_data:) + def initialize(channel, data:) @channel = channel - @reflex_data = reflex_data + @data = data @broadcaster = StimulusReflex::PageBroadcaster.new(self) @payload = {} @headers = {} @@ -75,7 +75,7 @@ def request req = ActionDispatch::Request.new(env) # fetch path params (controller, action, ...) and apply them - request_params = StimulusReflex::RequestParameters.new(params: reflex_data.params, req: req, url: url) + request_params = StimulusReflex::RequestParameters.new(params: data.params, req: req, url: url) req = request_params.apply! req