app/channels/stimulus_reflex/channel.rb in stimulus_reflex-3.5.0.pre2 vs app/channels/stimulus_reflex/channel.rb in stimulus_reflex-3.5.0.pre3

- old
+ new

@@ -22,19 +22,19 @@ error = exception_with_backtrace(exception) 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) - puts error_message - reflex.broadcast_message subject: "error", data: data, error: exception + reflex.logger&.error error_message + reflex.error data: data, body: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}" else - puts error_message + reflex.logger&.error error_message if body.to_s.include? "No route matches" initializer_path = Rails.root.join("config", "initializers", "stimulus_reflex.rb") - puts <<~NOTE + reflex.logger&.warn <<~NOTE \e[33mNOTE: StimulusReflex failed to locate a matching route and could not re-render the page. If your app uses Rack middleware to rewrite part of the request path, you must enable those middleware modules in StimulusReflex. The StimulusReflex initializer should be located at #{initializer_path}, or you can generate it with: @@ -52,26 +52,26 @@ end return end if reflex.halted? - reflex.broadcast_message subject: "halted", data: data + reflex.halted data: data else begin reflex.broadcast(reflex_data.selectors, data) rescue => exception reflex.rescue_with_handler(exception) error = exception_with_backtrace(exception) - reflex.broadcast_message subject: "error", data: data, error: exception - puts "\e[31mReflex failed to re-render: #{error[:message]} [#{reflex_data.url}]\e[0m\n#{error[:stack]}" + reflex.error data: data, body: "#{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 commit_session(reflex) report_failed_basic_auth(reflex) if reflex.controller? - reflex.logger&.print + reflex.logger&.log_all_operations end end end private @@ -95,22 +95,22 @@ def commit_session(reflex) store = reflex.request.session.instance_variable_get("@by") store.commit_session reflex.request, reflex.controller.response rescue => exception error = exception_with_backtrace(exception) - puts "\e[31mFailed to commit session! #{error[:message]}\e[0m\n#{error[:backtrace]}" + reflex.logger&.error "\e[31mFailed to commit session! #{error[:message]}\e[0m\n#{error[:backtrace]}" end def report_failed_basic_auth(reflex) if reflex.controller.response.status == 401 - puts "\e[31mReflex failed to process controller action \"#{reflex.controller.class}##{reflex.controller.action_name}\" due to HTTP basic auth. Consider adding \"unless: -> { @stimulus_reflex }\" to the before_action or method responible for authentication.\e[0m" + reflex.logger&.error "\e[31mReflex failed to process controller action \"#{reflex.controller.class}##{reflex.controller.action_name}\" due to HTTP basic auth. Consider adding \"unless: -> { @stimulus_reflex }\" to the before_action or method responible for authentication.\e[0m" end end def exception_with_backtrace(exception) { message: exception.to_s, - backtrace: exception.backtrace.first, + backtrace: exception.backtrace.first.split(":in ")[0], stack: exception.backtrace.join("\n") } end end