lib/ably/realtime/connection/connection_state_machine.rb in ably-0.7.2 vs lib/ably/realtime/connection/connection_state_machine.rb in ably-0.7.4

- old
+ new

@@ -38,12 +38,20 @@ after_transition(to: [:connecting], from: [:disconnected, :suspended]) do |connection| connection.manager.reconnect_transport end + before_transition(to: [:connected]) do |connection, current_transition| + connection.manager.connected current_transition.metadata + end + after_transition(to: [:connected]) do |connection, current_transition| - connection.manager.connected_with_error current_transition.metadata if current_transition.metadata + protocol_message = current_transition.metadata + if is_error_type?(protocol_message.error) + connection.logger.warn "ConnectionManager: Connected with error - #{protocol_message.error.message}" + connection.trigger :error, protocol_message.error + end end after_transition(to: [:disconnected, :suspended], from: [:connecting]) do |connection, current_transition| connection.manager.respond_to_transport_disconnected_when_connecting current_transition end @@ -71,12 +79,26 @@ before_transition(to: [:closed], from: [:closing]) do |connection| connection.manager.destroy_transport end # Transitions responsible for updating connection#error_reason - before_transition(to: [:connected, :closed, :disconnected, :suspended, :failed]) do |connection, current_transition| - reason = current_transition.metadata if is_error_type?(current_transition.metadata) - connection.set_failed_connection_error_reason reason + before_transition(to: [:disconnected, :suspended, :failed]) do |connection, current_transition| + connection.set_failed_connection_error_reason current_transition.metadata + end + + before_transition(to: [:connected, :closed]) do |connection, current_transition| + error = if current_transition.metadata.kind_of?(Ably::Models::ProtocolMessage) + current_transition.metadata.error + else + current_transition.metadata + end + + if is_error_type?(error) + connection.set_failed_connection_error_reason error + else + # Connected & Closed are "healthy" final states so reset the error reason + connection.clear_error_reason + end end private def connection object