diff --git a/lib/factiva/client.rb b/lib/factiva/client.rb index 971f637..886ec04 100644 --- a/lib/factiva/client.rb +++ b/lib/factiva/client.rb @@ -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 diff --git a/lib/factiva/errors.rb b/lib/factiva/errors.rb index 23f73ec..9375e06 100644 --- a/lib/factiva/errors.rb +++ b/lib/factiva/errors.rb @@ -1,3 +1,5 @@ module Factiva - class RequestError < StandardError; end + class Error < StandardError; end + class RequestError < Error; end + class TimeoutError < Error; end end diff --git a/spec/factiva/authentication_spec.rb b/spec/factiva/authentication_spec.rb index 0827c3c..26a6797 100644 --- a/spec/factiva/authentication_spec.rb +++ b/spec/factiva/authentication_spec.rb @@ -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 diff --git a/spec/factiva/monitoring_spec.rb b/spec/factiva/monitoring_spec.rb index 8d7a0f1..7a786c4 100644 --- a/spec/factiva/monitoring_spec.rb +++ b/spec/factiva/monitoring_spec.rb @@ -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 diff --git a/spec/factiva/request_spec.rb b/spec/factiva/request_spec.rb index 4ae0131..d119ed5 100644 --- a/spec/factiva/request_spec.rb +++ b/spec/factiva/request_spec.rb @@ -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 @@ -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