[backend/federation] Improve logging on activity fetch failures
This commit is contained in:
parent
bc0f585029
commit
a56e9b2922
2 changed files with 23 additions and 4 deletions
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue