From c91d7cf7a7b2e03d94fa2edcd70c1dd81069b71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20=C5=9Aliwa?= Date: Mon, 30 Aug 2021 16:43:49 +0200 Subject: [PATCH] [#275] Added request_id and cause attributes to the ErrorInfo class (TI1, RSC7c) --- lib/ably/models/error_info.rb | 8 ++++++-- spec/unit/models/error_info_spec.rb | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/ably/models/error_info.rb b/lib/ably/models/error_info.rb index 6ddc3d494..4057b1bfe 100644 --- a/lib/ably/models/error_info.rb +++ b/lib/ably/models/error_info.rb @@ -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 # @@ -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 @@ -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) - "#{see_msg}" + "#{see_msg}" end end end diff --git a/spec/unit/models/error_info_spec.rb b/spec/unit/models/error_info_spec.rb index 11f17a311..b4c2c0572 100644 --- a/spec/unit/models/error_info_spec.rb +++ b/spec/unit/models/error_info_spec.rb @@ -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 @@ -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) }