lib/submodules/ably-ruby/lib/ably/models/error_info.rb in ably-rest-1.0.6 vs lib/submodules/ably-ruby/lib/ably/models/error_info.rb in ably-rest-1.1.0

- old
+ new

@@ -1,5 +1,24 @@ +module Ably::Modules + module Conversions + private + # Convert error_details argument to a {ErrorInfo} object + # + # @param error_details [ErrorInfo,Hash] Error info attributes + # + # @return [ErrorInfo] + def ErrorInfo(error_details) + case error_details + when Ably::Models::ErrorInfo + error_details + else + Ably::Models::ErrorInfo.new(error_details) + end + end + end +end + module Ably::Models # An exception type encapsulating error information containing # an Ably-specific error code and generic status code. # # @!attribute [r] message @@ -17,11 +36,11 @@ def initialize(hash_object) @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(hash_object.clone.freeze) end - %w(message code status_code).each do |attribute| + %w(message code href status_code).each do |attribute| define_method attribute do attributes[attribute.to_sym] end end alias_method :status, :status_code @@ -29,9 +48,11 @@ def attributes @hash_object end def to_s - "Error: #{message} (code: #{code}, http status: #{status})" + error_href = href || (code ? "https://help.ably.io/error/#{code}" : '') + see_msg = " -> see #{error_href} for help" unless message.to_s.include?(error_href.to_s) + "<Error: #{message} (code: #{code}, http status: #{status})>#{see_msg}" end end end