DEV: Supress logs when RetrieveTitle.crawl fails with Net::ReadTimeout errors (#16971)

This PR changes the rescue block to rescue only Net::TimeoutError exceptions and removes the log line to prevent clutter the logs with errors that are ignored. Other errors can bubble up because they're errors we probably want to know about
This commit is contained in:
Sérgio Saquetim 2022-06-09 16:30:22 -03:00 committed by GitHub
parent 9cd165d6b4
commit 300f835703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -9,10 +9,8 @@ module RetrieveTitle
max_redirects: max_redirects, max_redirects: max_redirects,
initial_https_redirect_ignore_limit: initial_https_redirect_ignore_limit initial_https_redirect_ignore_limit: initial_https_redirect_ignore_limit
) )
rescue Exception => ex rescue Net::ReadTimeout
raise if Rails.env.test? # do nothing for Net::ReadTimeout errors
Rails.logger.error(ex)
nil
end end
def self.extract_title(html, encoding = nil) def self.extract_title(html, encoding = nil)

View File

@ -142,6 +142,18 @@ describe RetrieveTitle do
expect(RetrieveTitle.crawl("https://example.com")).to eq(nil) expect(RetrieveTitle.crawl("https://example.com")).to eq(nil)
end end
it "it raises errors other than Net::ReadTimeout, e.g. NoMethodError" do
stub_request(:get, "https://example.com").to_raise(NoMethodError)
expect { RetrieveTitle.crawl("https://example.com") }.to raise_error(NoMethodError)
end
it "it ignores Net::ReadTimeout errors" do
stub_request(:get, "https://example.com").to_raise(Net::ReadTimeout)
expect { RetrieveTitle.crawl("https://example.com") }.not_to raise_error(Net::ReadTimeout)
end
end end
context 'fetch_title' do context 'fetch_title' do