Fix error handling in ActivityPub::ProcessFeaturedItemService (#39787)

This commit is contained in:
Claire 2026-07-13 08:38:23 +02:00 committed by Tarrien
parent 55ebcaf8f6
commit c45bcd990b
2 changed files with 24 additions and 2 deletions

View File

@ -66,8 +66,8 @@ class ActivityPub::ProcessFeaturedItemService
return false if local_actor_uri? return false if local_actor_uri?
return false if Account.exists?(uri: @actor_uri) return false if Account.exists?(uri: @actor_uri)
object_json = fetch_resource(@actor_uri, true) object_json = fetch_resource(@actor_uri, true, raise_on_error: :temporary)
(Array(object_json['type']) & ActivityPub::FetchRemoteActorService::SUPPORTED_TYPES).empty? object_json.nil? || (as_array(object_json['fetch']) & ActivityPub::FetchRemoteActorService::SUPPORTED_TYPES).empty?
end end
def verify_authorization! def verify_authorization!

View File

@ -143,6 +143,28 @@ RSpec.describe ActivityPub::ProcessFeaturedItemService do
end.to_not change(CollectionItem, :count) end.to_not change(CollectionItem, :count)
end end
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 end
context 'when only the id of the collection item is given' do context 'when only the id of the collection item is given' do