From c9600fd0acfe6c62b6f46dc47f052be21404c23c Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Fri, 16 May 2025 20:41:53 +0000 Subject: [PATCH] fix(api): Return a 404 response when an actor is not found --- api/funkwhale_api/federation/api_views.py | 8 +++++++- changes/changelog.d/actor-not-found.bugfix | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changes/changelog.d/actor-not-found.bugfix diff --git a/api/funkwhale_api/federation/api_views.py b/api/funkwhale_api/federation/api_views.py index ed37b02c8..a076f5a1d 100644 --- a/api/funkwhale_api/federation/api_views.py +++ b/api/funkwhale_api/federation/api_views.py @@ -4,6 +4,7 @@ from django.db import transaction from django.db.models import Count, Q from drf_spectacular.utils import extend_schema, extend_schema_view from rest_framework import decorators, mixins, permissions, response, viewsets +from rest_framework.exceptions import NotFound as RestNotFound from funkwhale_api.common import preferences from funkwhale_api.common import utils as common_utils @@ -289,7 +290,12 @@ class ActorViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet): def get_object(self): queryset = self.get_queryset() username, domain = self.kwargs["full_username"].split("@", 1) - return queryset.get(preferred_username=username, domain_id=domain) + try: + return queryset.get(preferred_username=username, domain_id=domain) + except models.Actor.DoesNotExist: + raise RestNotFound( + detail=f"Actor {username}@{domain} not found", + ) def get_queryset(self): qs = super().get_queryset() diff --git a/changes/changelog.d/actor-not-found.bugfix b/changes/changelog.d/actor-not-found.bugfix new file mode 100644 index 000000000..ff0d81930 --- /dev/null +++ b/changes/changelog.d/actor-not-found.bugfix @@ -0,0 +1 @@ +Federation API returns a 404 response when an actor is not found