[backend/federation] Improve error handling in InboxValidationMiddleware
This commit is contained in:
parent
13955e7efe
commit
0e8aa8963c
1 changed files with 13 additions and 5 deletions
|
@ -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}");
|
||||||
|
|
Loading…
Add table
Reference in a new issue