Skip to content

Commit

Permalink
feat: change badge timeout message from error to warning
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Dec 18, 2019
1 parent eb8881f commit e34f567
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/pact_broker/badges/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ def dynamic_svg left_text, right_text, color
begin
response = do_request(uri)
response.code == '200' ? response.body : nil
rescue Net::OpenTimeout => e
logger.warn "Timeout retrieving badge from #{uri} #{e.class} - #{e.message}"
nil
rescue StandardError => e
logger.error "Error retrieving badge from #{uri} due to #{e.class} - #{e.message}"
log_error e, "Error retrieving badge from #{uri}"
nil
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/pact_broker/badges/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,25 @@ module Service
end
end

context "when a timeout exception is raised connecting to the shields.io server" do
before do
allow(Net::HTTP).to receive(:start).and_raise(Net::OpenTimeout)
end

it "logs a warning rather than an error as this will happen reasonably often" do
expect(logger).to receive(:warn).with(/Timeout retrieving badge from.*shield.*Net::OpenTimeout/)
subject
end

it "returns a static image" do
expect(subject).to include ">pact</"
end

it "does not cache the response" do
expect(Service::CACHE.size).to eq 0
end
end

context "when an exception is raised connecting to the shields.io server" do
before do
allow(Net::HTTP).to receive(:start).and_raise("an error")
Expand Down

0 comments on commit e34f567

Please sign in to comment.