[backend/federation] Improve logging on activity fetch failures

This commit is contained in:
Laura Hausmann 2024-02-17 18:25:32 +01:00
parent bc0f585029
commit a56e9b2922
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 23 additions and 4 deletions

View file

@ -9,7 +9,12 @@ using Newtonsoft.Json.Linq;
namespace Iceshrimp.Backend.Core.Federation.ActivityPub;
public class ActivityFetcherService(HttpClient client, HttpRequestService httpRqSvc, SystemUserService systemUserSvc)
public class ActivityFetcherService(
HttpClient client,
HttpRequestService httpRqSvc,
SystemUserService systemUserSvc,
ILogger<ActivityFetcherService> logger
)
{
private static readonly IReadOnlyCollection<string> AcceptableActivityTypes =
[
@ -31,9 +36,18 @@ public class ActivityFetcherService(HttpClient client, HttpRequestService httpRq
var request = httpRqSvc.GetSigned(url, AcceptableActivityTypes, actor, keypair);
var response = await client.SendAsync(request);
if (!response.IsSuccessStatusCode) return [];
if (!IsValidActivityContentType(response.Content.Headers.ContentType))
if (!response.IsSuccessStatusCode)
{
logger.LogDebug("Failed to fetch activity: response status was {code}", response.StatusCode);
return [];
}
if (!IsValidActivityContentType(response.Content.Headers.ContentType))
{
logger.LogDebug("Failed to fetch activity: content type {type} is invalid",
response.Content.Headers.ContentType);
return [];
}
var finalUri = response.RequestMessage?.RequestUri ??
throw new Exception("RequestMessage must not be null at this stage");

View file

@ -526,7 +526,12 @@ public class NoteService(
//TODO: should we fall back to a regular user's keypair if fetching with instance actor fails & a local user is following the actor?
fetchedNote ??= await fetchSvc.FetchNoteAsync(uri);
if (fetchedNote?.AttributedTo is not [{ Id: not null } attrTo])
if (fetchedNote == null)
{
logger.LogDebug("Failed to fetch note, skipping");
return null;
}
if (fetchedNote.AttributedTo is not [{ Id: not null } attrTo])
{
logger.LogDebug("Invalid Note.AttributedTo, skipping");
return null;