From 3832e9356db19d2b255acb5b73ba2d3af121ddbc Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Fri, 17 Apr 2020 13:11:08 -0500 Subject: [PATCH] rescue Addressable::URI::InvalidURIError and mark podcast ep unreachable (#7343) --- app/services/podcasts/get_media_url.rb | 2 +- spec/services/podcasts/get_media_url_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/services/podcasts/get_media_url.rb b/app/services/podcasts/get_media_url.rb index 235dbcd9f..4759dde5f 100644 --- a/app/services/podcasts/get_media_url.rb +++ b/app/services/podcasts/get_media_url.rb @@ -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 diff --git a/spec/services/podcasts/get_media_url_spec.rb b/spec/services/podcasts/get_media_url_spec.rb index 9554fc1e9..c2cc631e7 100644 --- a/spec/services/podcasts/get_media_url_spec.rb +++ b/spec/services/podcasts/get_media_url_spec.rb @@ -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