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:
parent
9cd165d6b4
commit
300f835703
|
@ -9,10 +9,8 @@ module RetrieveTitle
|
|||
max_redirects: max_redirects,
|
||||
initial_https_redirect_ignore_limit: initial_https_redirect_ignore_limit
|
||||
)
|
||||
rescue Exception => ex
|
||||
raise if Rails.env.test?
|
||||
Rails.logger.error(ex)
|
||||
nil
|
||||
rescue Net::ReadTimeout
|
||||
# do nothing for Net::ReadTimeout errors
|
||||
end
|
||||
|
||||
def self.extract_title(html, encoding = nil)
|
||||
|
|
|
@ -142,6 +142,18 @@ describe RetrieveTitle do
|
|||
|
||||
expect(RetrieveTitle.crawl("https://example.com")).to eq(nil)
|
||||
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
|
||||
|
||||
context 'fetch_title' do
|
||||
|
|
Loading…
Reference in New Issue