mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FIX: Don’t raise an error on onebox timeouts
Currently when generating oneboxes if the connection timeouts and we’re using the `FinalDestination#get` method, then it raises an exception. We already catch this exception when using the `FinalDestination#resolve` method so this patch just applies the same logic to `FinalDestination#get`.
This commit is contained in:
parent
1dff3ad79d
commit
1f5682b7d7
|
@ -518,6 +518,9 @@ class FinalDestination
|
||||||
end
|
end
|
||||||
|
|
||||||
result
|
result
|
||||||
|
rescue Timeout::Error
|
||||||
|
log(:warn, "FinalDestination could not resolve URL (timeout): #{@uri}") if @verbose
|
||||||
|
nil
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
unsafe_close ? [:ok, headers_subset] : raise
|
unsafe_close ? [:ok, headers_subset] : raise
|
||||||
end
|
end
|
||||||
|
|
|
@ -424,28 +424,46 @@ describe FinalDestination do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.get' do
|
describe '#get' do
|
||||||
|
let(:fd) { FinalDestination.new("http://wikipedia.com", opts.merge(verbose: true)) }
|
||||||
|
|
||||||
it "can correctly stream with a redirect" do
|
context "when there is a redirect" do
|
||||||
FinalDestination.clear_https_cache!("wikipedia.com")
|
before do
|
||||||
|
described_class.clear_https_cache!("wikipedia.com")
|
||||||
stub_request(:get, "http://wikipedia.com/").
|
stub_request(:get, "http://wikipedia.com/").
|
||||||
to_return(status: 302, body: "" , headers: { "location" => "https://wikipedia.com/" })
|
to_return(status: 302, body: "" , headers: { "location" => "https://wikipedia.com/" })
|
||||||
|
# webmock does not do chunks
|
||||||
# webmock does not do chunks
|
stub_request(:get, "https://wikipedia.com/").
|
||||||
stub_request(:get, "https://wikipedia.com/").
|
to_return(status: 200, body: "<html><head>" , headers: {})
|
||||||
to_return(status: 200, body: "<html><head>" , headers: {})
|
|
||||||
|
|
||||||
result = nil
|
|
||||||
chunk = nil
|
|
||||||
|
|
||||||
result = FinalDestination.new("http://wikipedia.com", opts).get do |resp, c|
|
|
||||||
chunk = c
|
|
||||||
throw :done
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(result).to eq("https://wikipedia.com/")
|
it "correctly streams" do
|
||||||
expect(chunk).to eq("<html><head>")
|
chunk = nil
|
||||||
|
result = fd.get do |resp, c|
|
||||||
|
chunk = c
|
||||||
|
throw :done
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(result).to eq("https://wikipedia.com/")
|
||||||
|
expect(chunk).to eq("<html><head>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when there is a timeout" do
|
||||||
|
subject(:get) { fd.get {} }
|
||||||
|
|
||||||
|
before do
|
||||||
|
fd.stubs(:safe_session).raises(Timeout::Error)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "logs the exception" do
|
||||||
|
Rails.logger.expects(:warn).with("default: FinalDestination could not resolve URL (timeout): https://wikipedia.com")
|
||||||
|
get
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nothing" do
|
||||||
|
expect(get).to be_blank
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user