diff --git a/lib/skyfall/errors.rb b/lib/skyfall/errors.rb index 35e0d79..3e7a328 100644 --- a/lib/skyfall/errors.rb +++ b/lib/skyfall/errors.rb @@ -6,16 +6,15 @@ module Skyfall end # - # Raised when some part of the message being decoded has invalid format. + # Raised when some code is not configured or configured incorrectly. # - class DecodeError < Error + class ConfigError < Error end # - # Raised when the server sends a message which is formatted correctly, but written in a version - # that's not supported by this library. + # Raised when some part of the message being decoded has invalid format. # - class UnsupportedError < Error + class DecodeError < Error end # @@ -61,4 +60,11 @@ module Skyfall super("Subscription error: #{error_type}" + (error_message ? " (#{error_message})" : "")) end end + + # + # Raised when the server sends a message which is formatted correctly, but written in a version + # that's not supported by this library. + # + class UnsupportedError < Error + end end diff --git a/lib/skyfall/stream.rb b/lib/skyfall/stream.rb index 7023c18..acdcb3b 100644 --- a/lib/skyfall/stream.rb +++ b/lib/skyfall/stream.rb @@ -2,6 +2,7 @@ require 'eventmachine' require 'faye/websocket' require 'uri' +require_relative 'errors' require_relative 'events' require_relative 'version' @@ -99,11 +100,16 @@ module Skyfall # once the connection is closed. # # @return [nil] + # @raise [ConfigError] if no message handler has been configured # @raise [ReactorActiveError] if another stream is already running # def connect return if @ws + if @handlers[:message].nil? && @handlers[:raw_message].nil? + raise ConfigError, "Either on_message or on_raw_message handler needs to be set" + end + url = build_websocket_url @handlers[:connecting]&.call(url)