From 8c4c782c78b45d94e97ee9a26a05c44cae7cd428 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 6 Apr 2015 15:38:22 -0500 Subject: Catch exceptions when subscribing to a channel and processing a message --- lib/action_cable/connection/base.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/action_cable') diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index c5b982acf8..ea5d52e99c 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -105,23 +105,29 @@ module ActionCable subscription_klass = server.registered_channels.detect { |channel_klass| channel_klass.find_name == id_options[:channel] } if subscription_klass - logger.info "Subscribing to channel: #{id_key}" + logger.info "[ActionCable] Subscribing to channel: #{id_key}" @subscriptions[id_key] = subscription_klass.new(self, id_key, id_options) else - logger.error "Unable to subscribe to channel: #{id_key}" + logger.error "[ActionCable] Subscription class not found (#{data.inspect})" end + rescue Exception => e + logger.error "[ActionCable] Could not subscribe to channel (#{data.inspect})" + logger.error e.backtrace.join("\n") end def process_message(message) if @subscriptions[message['identifier']] @subscriptions[message['identifier']].receive_data(ActiveSupport::JSON.decode message['data']) else - logger.error "Unable to process message: #{message}" + logger.error "[ActionCable] Unable to process message because no subscription found (#{message.inspect})" end + rescue Exception => e + logger.error "[ActionCable] Could not process message (#{data.inspect})" + logger.error e.backtrace.join("\n") end def unsubscribe_channel(data) - logger.info "Unsubscribing from channel: #{data['identifier']}" + logger.info "[ActionCable] Unsubscribing from channel: #{data['identifier']}" @subscriptions[data['identifier']].unsubscribe @subscriptions.delete(data['identifier']) end -- cgit v1.2.3