[backend/federation] Log instance blocked failures in inbox queue as debug
This commit is contained in:
parent
bc270d4fed
commit
0a5e130783
4 changed files with 30 additions and 4 deletions
|
@ -34,7 +34,7 @@ public class ActivityHandlerService(
|
||||||
if (activity.Actor == null)
|
if (activity.Actor == null)
|
||||||
throw GracefulException.UnprocessableEntity("Cannot perform activity as actor 'null'");
|
throw GracefulException.UnprocessableEntity("Cannot perform activity as actor 'null'");
|
||||||
if (await federationCtrl.ShouldBlockAsync(activity.Actor.Id))
|
if (await federationCtrl.ShouldBlockAsync(activity.Actor.Id))
|
||||||
throw GracefulException.UnprocessableEntity("Instance is blocked");
|
throw new InstanceBlockedException(activity.Actor.Id);
|
||||||
if (activity.Object == null && activity is not ASBite)
|
if (activity.Object == null && activity is not ASBite)
|
||||||
throw GracefulException.UnprocessableEntity("Activity object is null");
|
throw GracefulException.UnprocessableEntity("Activity object is null");
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class ObjectResolver(
|
||||||
|
|
||||||
if (await federationCtrl.ShouldBlockAsync(baseObj.Id))
|
if (await federationCtrl.ShouldBlockAsync(baseObj.Id))
|
||||||
{
|
{
|
||||||
logger.LogDebug("Instance is blocked");
|
logger.LogDebug("Instance is blocked ({uri})", baseObj.Id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,21 @@ public class LocalFetchException(string uri)
|
||||||
public string Uri => uri;
|
public string Uri => uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class InstanceBlockedException(string uri, string? host = null)
|
||||||
|
: GracefulException(HttpStatusCode.UnprocessableEntity, "Instance is blocked")
|
||||||
|
{
|
||||||
|
public string? Host
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (host != null) return host;
|
||||||
|
return System.Uri.TryCreate(uri, UriKind.Absolute, out var res) ? res.Host : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Uri => uri;
|
||||||
|
}
|
||||||
|
|
||||||
public enum ExceptionVerbosity
|
public enum ExceptionVerbosity
|
||||||
{
|
{
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
|
|
|
@ -25,7 +25,18 @@ public class InboxQueue(int parallelism)
|
||||||
throw new GracefulException("Job data is not an ASActivity", $"Type: {obj.Type}");
|
throw new GracefulException("Job data is not an ASActivity", $"Type: {obj.Type}");
|
||||||
|
|
||||||
var apHandler = scope.GetRequiredService<ActivityPub.ActivityHandlerService>();
|
var apHandler = scope.GetRequiredService<ActivityPub.ActivityHandlerService>();
|
||||||
await apHandler.PerformActivityAsync(activity, jobData.InboxUserId, jobData.AuthenticatedUserId);
|
try
|
||||||
|
{
|
||||||
|
await apHandler.PerformActivityAsync(activity, jobData.InboxUserId, jobData.AuthenticatedUserId);
|
||||||
|
}
|
||||||
|
catch (InstanceBlockedException e)
|
||||||
|
{
|
||||||
|
var logger = scope.GetRequiredService<ILogger<InboxQueue>>();
|
||||||
|
if (e.Host != null)
|
||||||
|
logger.LogDebug("Refusing to process activity {id}: Instance {host} is blocked", job.Id, e.Host);
|
||||||
|
else
|
||||||
|
logger.LogDebug("Refusing to process activity {id}: Instance is blocked ({uri})", job.Id, e.Uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue