rescue Addressable::URI::InvalidURIError and mark podcast ep unreachable (#7343)

This commit is contained in:
Molly Struve 2020-04-17 13:11:08 -05:00 committed by GitHub
parent 1b93666b3b
commit 3832e9356d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -35,7 +35,7 @@ module Podcasts
def url_reachable?(url)
url = Addressable::URI.parse(url).normalize.to_s
HTTParty.head(url).code == 200
rescue Net::OpenTimeout, SystemCallError, URI::InvalidURIError
rescue Net::OpenTimeout, SystemCallError, URI::InvalidURIError, Addressable::URI::InvalidURIError
false
end
end

View file

@ -74,4 +74,13 @@ RSpec.describe Podcasts::GetMediaUrl, type: :service do
expect(result.reachable).to be false
expect(result.url).to eq(http_url)
end
it "marks unreachable with addressable invalid url exception" do
allow(HTTParty).to receive(:head).with(https_url).and_raise(Addressable::URI::InvalidURIError)
allow(HTTParty).to receive(:head).with(http_url).and_raise(Addressable::URI::InvalidURIError)
result = described_class.call(http_url)
expect(result.https).to be false
expect(result.reachable).to be false
expect(result.url).to eq(http_url)
end
end