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 8, 2024
1 parent 2c86d41 commit 3630ce8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/factiva/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def make_request(params)
end

response_body
rescue HTTP::TimeoutError
# This error should be handled before HTTP::Error which is a superclass of HTTP::TimeoutError
# Raising Factiva::TimeoutError is required for CircuitBreaker to work properly
raise Factiva::TimeoutError
end

def expired?(timestamp)
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 lib/factiva/monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,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: 2 additions & 2 deletions lib/factiva/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def make_request(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: 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 @@ -171,10 +171,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 3630ce8

Please sign in to comment.