From 8abbae190616b56679f60c4169cdbf522852b977 Mon Sep 17 00:00:00 2001 From: Alexey Cherepanov Date: Wed, 9 Feb 2022 02:29:08 +0400 Subject: [PATCH 1/2] Raise `SolanaRpcRuby::ApiError` on `Net::HTTPTooManyRequests` --- lib/solana_rpc_ruby/api_client.rb | 1 + spec/lib/solana_rpc_ruby/api_client_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/solana_rpc_ruby/api_client.rb b/lib/solana_rpc_ruby/api_client.rb index ea0cd77..3169950 100644 --- a/lib/solana_rpc_ruby/api_client.rb +++ b/lib/solana_rpc_ruby/api_client.rb @@ -53,6 +53,7 @@ def call_api(body:, http_method:, params: {}) Net::HTTPNotFound, Net::HTTPClientException, Net::HTTPFatalError, + Net::HTTPTooManyRequests, Net::ReadTimeout, Errno::ECONNREFUSED, SocketError => e diff --git a/spec/lib/solana_rpc_ruby/api_client_spec.rb b/spec/lib/solana_rpc_ruby/api_client_spec.rb index 6edf64e..5fc022b 100644 --- a/spec/lib/solana_rpc_ruby/api_client_spec.rb +++ b/spec/lib/solana_rpc_ruby/api_client_spec.rb @@ -88,6 +88,18 @@ end end + describe 'Net::HTTPTooManyRequests' do + it 'raise error correctly' do + allow(http).to \ + receive(:request).with(an_instance_of(Net::HTTP::Post)) + .and_raise(Net::HTTPTooManyRequests.new('Net::HTTPTooManyRequests', 'Response')) + + expect do + described_class.new.call_api(body: {}, http_method: :post) + end.to raise_error(SolanaRpcRuby::ApiError, 'Net::HTTPTooManyRequests') + end + end + describe 'Net::ReadTimeout' do it 'raise error correctly' do allow(http).to \ From a2c625d12ab40209e846efc33c42dc4910a5ed9f Mon Sep 17 00:00:00 2001 From: Alexey Cherepanov Date: Thu, 10 Feb 2022 17:23:46 +0400 Subject: [PATCH 2/2] Update api_client_spec.rb Fix `Net::HTTPTooManyRequests` initialisation. --- spec/lib/solana_rpc_ruby/api_client_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/solana_rpc_ruby/api_client_spec.rb b/spec/lib/solana_rpc_ruby/api_client_spec.rb index 5fc022b..feba1f8 100644 --- a/spec/lib/solana_rpc_ruby/api_client_spec.rb +++ b/spec/lib/solana_rpc_ruby/api_client_spec.rb @@ -92,7 +92,7 @@ it 'raise error correctly' do allow(http).to \ receive(:request).with(an_instance_of(Net::HTTP::Post)) - .and_raise(Net::HTTPTooManyRequests.new('Net::HTTPTooManyRequests', 'Response')) + .and_raise(Net::HTTPTooManyRequests.new('1.1', 429, '')) expect do described_class.new.call_api(body: {}, http_method: :post)