Skip to content

Commit

Permalink
feat: raise custom timeout error
Browse files Browse the repository at this point in the history
  • Loading branch information
uncoder committed Oct 3, 2024
1 parent 61b27a7 commit 645c4e8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/factiva/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def make_request(http_method, url, params = nil)
end
rescue HTTP::TimeoutError
# This error should be handled before HTTP::Error which is a superclass of HTTP::TimeoutError
# Raising HTTP::TimeoutError is required for CircuitBreaker to work properly
raise
# Raising Factiva::TimeoutError is required for CircuitBreaker to work properly
raise Factiva::TimeoutError
rescue SocketError, HTTP::Error => error
Failure("Failed to connect to Factiva: #{error.message}")
rescue JSON::ParserError => error
Expand Down
4 changes: 3 additions & 1 deletion lib/factiva/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Factiva
class RequestError < StandardError; end
class Error < StandardError; end
class RequestError < Error; end
class TimeoutError < Error; end
end
4 changes: 2 additions & 2 deletions spec/factiva/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ module Factiva
WebMock.stub_request(:post, /oauth2\/v1\/token/).to_timeout
end

it "raises HTTP::TimeoutError for CircuitBreaker" do
expect { subject.token }.to raise_error(HTTP::TimeoutError)
it "raises Factiva::TimeoutError for CircuitBreaker" do
expect { subject.token }.to raise_error(Factiva::TimeoutError)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/factiva/monitoring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ module Factiva
WebMock.stub_request(:get, /risk-entity-screening-cases/).to_timeout
end

it "raises HTTP::TimeoutError for CircuitBreaker" do
it "raises Factiva::TimeoutError for CircuitBreaker" do
expect {
subject.get_matches(case_id: "id")
}.to raise_error(HTTP::TimeoutError)
}.to raise_error(Factiva::TimeoutError)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/factiva/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ module Factiva
WebMock.stub_request(:post, /riskentities\/search/).to_timeout
end

it "raises HTTP::TimeoutError for CircuitBreaker" do
it "raises Factiva::TimeoutError for CircuitBreaker" do
expect {
subject.search(**params)
}.to raise_error(HTTP::TimeoutError)
}.to raise_error(Factiva::TimeoutError)
end
end
end
Expand Down Expand Up @@ -184,10 +184,10 @@ module Factiva
WebMock.stub_request(:get, /riskentities\/profiles/).to_timeout
end

it "raises HTTP::TimeoutError for CircuitBreaker" do
it "raises Factiva::TimeoutError for CircuitBreaker" do
expect {
subject.profile(profile_id)
}.to raise_error(HTTP::TimeoutError)
}.to raise_error(Factiva::TimeoutError)
end
end
end
Expand Down

0 comments on commit 645c4e8

Please sign in to comment.