[backend/federation] Improve error handling in InboxValidationMiddleware

This commit is contained in:
Laura Hausmann 2024-10-23 17:47:28 +02:00
parent 13955e7efe
commit 0e8aa8963c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -76,6 +76,7 @@ public class InboxValidationMiddleware(
try try
{ {
expanded = LdHelpers.Expand(parsed); expanded = LdHelpers.Expand(parsed);
if (expanded == null) throw new Exception("Failed to expand ASObject");
} }
catch (Exception e) catch (Exception e)
{ {
@ -83,11 +84,18 @@ public class InboxValidationMiddleware(
return; return;
} }
if (expanded == null) ASObject? obj;
throw new Exception("Failed to expand ASObject"); try
var obj = ASObject.Deserialize(expanded); {
if (obj == null) obj = ASObject.Deserialize(expanded);
throw new Exception("Failed to deserialize ASObject"); if (obj == null) throw new Exception("Failed to deserialize ASObject");
}
catch (Exception e)
{
throw GracefulException
.UnprocessableEntity($"Failed to deserialize request body as ASObject: {e.Message}");
}
if (obj is not ASActivity activity) if (obj is not ASActivity activity)
throw new GracefulException(HttpStatusCode.UnprocessableEntity, throw new GracefulException(HttpStatusCode.UnprocessableEntity,
"Request body is not an ASActivity", $"Type: {obj.Type}"); "Request body is not an ASActivity", $"Type: {obj.Type}");