aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable/connection
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2015-06-22 16:20:06 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2015-06-22 16:20:06 +0200
commit72c16340bff9a79eecc2dd5e9291b199f5ae32ea (patch)
tree8bc2d460df742077c1780bb34dba6fc9a49b5cac /lib/action_cable/connection
parent82f13443a508600a94319ce0e636d04f0ed4673e (diff)
downloadrails-72c16340bff9a79eecc2dd5e9291b199f5ae32ea.tar.gz
rails-72c16340bff9a79eecc2dd5e9291b199f5ae32ea.tar.bz2
rails-72c16340bff9a79eecc2dd5e9291b199f5ae32ea.zip
Extract execute_command method and centralize exception handling
Diffstat (limited to 'lib/action_cable/connection')
-rw-r--r--lib/action_cable/connection/base.rb22
-rw-r--r--lib/action_cable/connection/subscriptions.rb2
2 files changed, 10 insertions, 14 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb
index 5951198f36..aa3eb6472d 100644
--- a/lib/action_cable/connection/base.rb
+++ b/lib/action_cable/connection/base.rb
@@ -39,15 +39,7 @@ module ActionCable
def receive(data_in_json)
if websocket_alive?
- data = decode_json data_in_json
-
- case data['command']
- when 'subscribe' then subscriptions.add data
- when 'unsubscribe' then subscriptions.remove data
- when 'message' then process_message data
- else
- logger.error "Received unrecognized command in #{data.inspect}"
- end
+ execute_command decode_json(data_in_json)
else
logger.error "Received data without a live websocket (#{data.inspect})"
end
@@ -113,10 +105,16 @@ module ActionCable
end
- def process_message(message)
- subscriptions.find(message['identifier']).perform_action decode_json(message['data'])
+ def execute_command(data)
+ case data['command']
+ when 'subscribe' then subscriptions.add data
+ when 'unsubscribe' then subscriptions.remove data
+ when 'message' then subscriptions.find(message['identifier']).perform_action decode_json(message['data'])
+ else
+ logger.error "Received unrecognized command in #{data.inspect}"
+ end
rescue Exception => e
- logger.error "Could not process message (#{message.inspect})"
+ logger.error "Could not execute command from #{data.inspect})"
log_exception(e)
end
diff --git a/lib/action_cable/connection/subscriptions.rb b/lib/action_cable/connection/subscriptions.rb
index 888b93a652..dbba8eca1d 100644
--- a/lib/action_cable/connection/subscriptions.rb
+++ b/lib/action_cable/connection/subscriptions.rb
@@ -19,8 +19,6 @@ module ActionCable
else
connection.logger.error "Subscription class not found (#{data.inspect})"
end
- rescue Exception => e
- connection.logger.error "Could not subscribe to channel (#{data.inspect}) due to '#{e}': #{e.backtrace.join(' - ')}"
end
def remove(data)