app/channels/stimulus_reflex/channel.rb in stimulus_reflex-3.5.0.pre9 vs app/channels/stimulus_reflex/channel.rb in stimulus_reflex-3.5.0.pre10
- old
+ new
@@ -2,11 +2,11 @@
class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.constantize
attr_reader :reflex_data
def stream_name
- [params[:channel], connection.connection_identifier].join(":")
+ [params[:channel], connection.connection_identifier].reject(&:blank?).join(":")
end
def subscribed
super
stream_from stream_name
@@ -23,22 +23,22 @@
error_message = "\e[31mReflex #{reflex_data.target} failed: #{error[:message]} [#{reflex_data.url}]\e[0m\n#{error[:stack]}"
if reflex
reflex.rescue_with_handler(exception)
reflex.logger&.error error_message
- reflex.error data: data, body: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}"
+ reflex.broadcast_error data: data, error: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}"
else
if exception.is_a? StimulusReflex::Reflex::VersionMismatchError
mismatch = "Reflex failed due to stimulus_reflex gem/NPM package version mismatch. Package versions must match exactly.\nNote that if you are using pre-release builds, gems use the \"x.y.z.preN\" version format, while NPM packages use \"x.y.z-preN\".\n\nstimulus_reflex gem: #{StimulusReflex::VERSION}\nstimulus_reflex NPM: #{data["version"]}"
StimulusReflex.config.logger.error("\n\e[31m#{mismatch}\e[0m") unless StimulusReflex.config.on_failed_sanity_checks == :ignore
if Rails.env.development?
CableReady::Channels.instance[stream_name].console_log(
message: mismatch,
level: "error",
- reflex_id: data["reflexId"]
+ id: data["id"]
).broadcast
end
if StimulusReflex.config.on_failed_sanity_checks == :exit
sleep 0.1
@@ -46,11 +46,11 @@
end
else
StimulusReflex.config.logger.error error_message
end
- if body.to_s.include? "No route matches"
+ if error_message.to_s.include? "No route matches"
initializer_path = Rails.root.join("config", "initializers", "stimulus_reflex.rb")
StimulusReflex.config.logger.warn <<~NOTE
\e[33mNOTE: StimulusReflex failed to locate a matching route and could not re-render the page.
@@ -71,18 +71,20 @@
end
return
end
if reflex.halted?
- reflex.halted data: data
+ reflex.broadcast_halt data: data
+ elsif reflex.forbidden?
+ reflex.broadcast_forbid data: data
else
begin
reflex.broadcast(reflex_data.selectors, data)
rescue => exception
reflex.rescue_with_handler(exception)
error = exception_with_backtrace(exception)
- reflex.error data: data, body: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}"
+ reflex.broadcast_error data: data, error: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}"
reflex.logger&.error "\e[31mReflex failed to re-render: #{error[:message]} [#{reflex_data.url}]\e[0m\n#{error[:stack]}"
end
end
ensure
if reflex
@@ -110,10 +112,10 @@
raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{policy.required_params.inspect}, optional #{policy.optional_params.inspect})")
end
end
def commit_session(reflex)
- store = reflex.request.session.instance_variable_get("@by")
+ store = reflex.request.session.instance_variable_get(:@by)
store.commit_session reflex.request, reflex.controller.response
rescue => exception
error = exception_with_backtrace(exception)
reflex.logger&.error "\e[31mFailed to commit session! #{error[:message]}\e[0m\n#{error[:backtrace]}"
end