]> cat aescling's git repositories - mastodon.git/commitdiff
Fix temporary network/remote server error prevent from interactions with remote accou...
authorClaire <claire.github-309c@sitedethib.com>
Thu, 28 Apr 2022 18:19:10 +0000 (20:19 +0200)
committersingle-right-quote <11325618-aescling@users.noreply.gitlab.com>
Thu, 5 May 2022 17:49:12 +0000 (13:49 -0400)
* Fix temporary network/remote server error prevent from interactions with remote accounts

* Fix and add tests

app/services/resolve_url_service.rb
spec/services/resolve_url_service_spec.rb

index 5981e4d98a00fc4e2a958972bbfd84894a65e6ee..e2c745673e572db781a437fad6f6af247594d8af 100644 (file)
@@ -30,6 +30,11 @@ class ResolveURLService < BaseService
   end
 
   def process_url_from_db
+    if [500, 502, 503, 504, nil].include?(fetch_resource_service.response_code)
+      account = Account.find_by(uri: @url)
+      return account unless account.nil?
+    end
+
     return unless @on_behalf_of.present? && [401, 403, 404].include?(fetch_resource_service.response_code)
 
     # It may happen that the resource is a private toot, and thus not fetchable,
index a38b23590055f1cbd1076986da2753181e6bc821..1b639dea983c71ce96c94c9fdcf1b38904ae6ba9 100644 (file)
@@ -7,15 +7,29 @@ describe ResolveURLService, type: :service do
 
   describe '#call' do
     it 'returns nil when there is no resource url' do
-      url     = 'http://example.com/missing-resource'
+      url           = 'http://example.com/missing-resource'
+      known_account = Fabricate(:account, uri: url)
       service = double
 
       allow(FetchResourceService).to receive(:new).and_return service
+      allow(service).to receive(:response_code).and_return(404)
       allow(service).to receive(:call).with(url).and_return(nil)
 
       expect(subject.call(url)).to be_nil
     end
 
+    it 'returns known account on temporary error' do
+      url           = 'http://example.com/missing-resource'
+      known_account = Fabricate(:account, uri: url)
+      service = double
+
+      allow(FetchResourceService).to receive(:new).and_return service
+      allow(service).to receive(:response_code).and_return(500)
+      allow(service).to receive(:call).with(url).and_return(nil)
+
+      expect(subject.call(url)).to eq known_account
+    end
+
     context 'searching for a remote private status' do
       let(:account)  { Fabricate(:account) }
       let(:poster)   { Fabricate(:account, domain: 'example.com') }