[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;
|
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 =
|
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 request = httpRqSvc.GetSigned(url, AcceptableActivityTypes, actor, keypair);
|
||||||
var response = await client.SendAsync(request);
|
var response = await client.SendAsync(request);
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode) return [];
|
if (!response.IsSuccessStatusCode)
|
||||||
if (!IsValidActivityContentType(response.Content.Headers.ContentType))
|
{
|
||||||
|
logger.LogDebug("Failed to fetch activity: response status was {code}", response.StatusCode);
|
||||||
return [];
|
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 ??
|
var finalUri = response.RequestMessage?.RequestUri ??
|
||||||
throw new Exception("RequestMessage must not be null at this stage");
|
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?
|
//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);
|
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");
|
logger.LogDebug("Invalid Note.AttributedTo, skipping");
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue