From c45bcd990b235b4de4152973afc371d4aea8d4b2 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 13 Jul 2026 08:38:23 +0200 Subject: [PATCH] Fix error handling in `ActivityPub::ProcessFeaturedItemService` (#39787) --- .../process_featured_item_service.rb | 4 ++-- .../process_featured_item_service_spec.rb | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/services/activitypub/process_featured_item_service.rb b/app/services/activitypub/process_featured_item_service.rb index b9769cc037..fea25ca332 100644 --- a/app/services/activitypub/process_featured_item_service.rb +++ b/app/services/activitypub/process_featured_item_service.rb @@ -66,8 +66,8 @@ class ActivityPub::ProcessFeaturedItemService return false if local_actor_uri? return false if Account.exists?(uri: @actor_uri) - object_json = fetch_resource(@actor_uri, true) - (Array(object_json['type']) & ActivityPub::FetchRemoteActorService::SUPPORTED_TYPES).empty? + object_json = fetch_resource(@actor_uri, true, raise_on_error: :temporary) + object_json.nil? || (as_array(object_json['fetch']) & ActivityPub::FetchRemoteActorService::SUPPORTED_TYPES).empty? end def verify_authorization! diff --git a/spec/services/activitypub/process_featured_item_service_spec.rb b/spec/services/activitypub/process_featured_item_service_spec.rb index 5f071e364e..3b0f633fe0 100644 --- a/spec/services/activitypub/process_featured_item_service_spec.rb +++ b/spec/services/activitypub/process_featured_item_service_spec.rb @@ -143,6 +143,28 @@ RSpec.describe ActivityPub::ProcessFeaturedItemService do end.to_not change(CollectionItem, :count) end end + + context 'when featured object cannot be fetched' do + let(:hashtag_json) do + { + 'id' => 'https://example.com/hashtags/people', + 'type' => 'Hashtag', + 'name' => '#people', + } + end + let(:featured_object_uri) { hashtag_json['id'] } + + before do + stub_request(:get, featured_object_uri) + .to_return(status: 404) + end + + it 'does not create a collection item and returns `nil`' do + expect do + expect(subject.call(collection, object, position:)).to be_nil + end.to_not change(CollectionItem, :count) + end + end end context 'when only the id of the collection item is given' do