Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ably/models/error_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module Ably::Models
# @return [Integer] Ably error code (see ably-common/protocol/errors.json)
# @!attribute [r] status
# @return [Integer] HTTP Status Code corresponding to this error, where applicable
# @!attribute [r] request_id
# @return [Integer] HTTP RequestId corresponding to this error, where applicable (#RSC7c)
# @!attribute [r] cause
# @return [Integer] HTTP Status Code corresponding to this error, where applicable (#TI1)
# @!attribute [r] attributes
# @return [Hash] Access the protocol message Hash object ruby'fied to use symbolized keys
#
Expand All @@ -38,7 +42,7 @@ def initialize(hash_object)
@hash_object = IdiomaticRubyWrapper(hash_object.clone.freeze)
end

%w(message code href status_code).each do |attribute|
%w(message code href status_code request_id cause).each do |attribute|
define_method attribute do
attributes[attribute.to_sym]
end
Expand All @@ -52,7 +56,7 @@ def attributes
def to_s
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}"
"<Error: #{message} (code: #{code}, http status: #{status} request_id: #{request_id} cause: #{cause})>#{see_msg}"
end
end
end
18 changes: 17 additions & 1 deletion spec/unit/models/error_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
subject { Ably::Models::ErrorInfo }

context '#TI1, #TI4' do
it_behaves_like 'a model', with_simple_attributes: %w(code status_code href message) do
it_behaves_like 'a model', with_simple_attributes: %w(code status_code href message request_id cause) do
let(:model_args) { [] }
end
end
Expand All @@ -18,6 +18,22 @@
end
end

context '#request_id #RSC7c' do
subject { Ably::Models::ErrorInfo.new('request_id' => '123-456-789-001') }

it 'should return request ID' do
expect(subject.request_id).to eql('123-456-789-001')
end
end

context '#cause #TI1' do
subject { Ably::Models::ErrorInfo.new('cause' => Ably::Models::ErrorInfo.new({})) }

it 'should return cause attribute' do
expect(subject.cause).to be_kind_of(Ably::Models::ErrorInfo)
end
end

context 'log entries container help link #TI5' do
context 'without an error code' do
subject { Ably::Models::ErrorInfo.new('statusCode' => 401) }
Expand Down