Skip to content

Commit

Permalink
fix breaking issues
Browse files Browse the repository at this point in the history
Rename named parameter, and change rescue error message
  • Loading branch information
brunoenten committed Oct 8, 2023
1 parent 3137a0f commit 8d754b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/channels/stimulus_reflex/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/stimulus_reflex/reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d754b8

Please sign in to comment.