Skip to content

Commit e34f567

Browse files
committed
feat: change badge timeout message from error to warning
1 parent eb8881f commit e34f567

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/pact_broker/badges/service.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ def dynamic_svg left_text, right_text, color
8484
begin
8585
response = do_request(uri)
8686
response.code == '200' ? response.body : nil
87+
rescue Net::OpenTimeout => e
88+
logger.warn "Timeout retrieving badge from #{uri} #{e.class} - #{e.message}"
89+
nil
8790
rescue StandardError => e
88-
logger.error "Error retrieving badge from #{uri} due to #{e.class} - #{e.message}"
91+
log_error e, "Error retrieving badge from #{uri}"
8992
nil
9093
end
9194
end

spec/lib/pact_broker/badges/service_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,25 @@ module Service
219219
end
220220
end
221221

222+
context "when a timeout exception is raised connecting to the shields.io server" do
223+
before do
224+
allow(Net::HTTP).to receive(:start).and_raise(Net::OpenTimeout)
225+
end
226+
227+
it "logs a warning rather than an error as this will happen reasonably often" do
228+
expect(logger).to receive(:warn).with(/Timeout retrieving badge from.*shield.*Net::OpenTimeout/)
229+
subject
230+
end
231+
232+
it "returns a static image" do
233+
expect(subject).to include ">pact</"
234+
end
235+
236+
it "does not cache the response" do
237+
expect(Service::CACHE.size).to eq 0
238+
end
239+
end
240+
222241
context "when an exception is raised connecting to the shields.io server" do
223242
before do
224243
allow(Net::HTTP).to receive(:start).and_raise("an error")

0 commit comments

Comments
 (0)