handle exception in deserializer

This commit is contained in:
Nicolas Constant 2020-07-22 19:27:49 -04:00
parent 10104187d5
commit 66630324d7
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688

View file

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using Newtonsoft.Json;
namespace BirdsiteLive.ActivityPub
{
@ -6,41 +7,48 @@ namespace BirdsiteLive.ActivityPub
{
public static Activity ProcessActivity(string json)
{
var activity = JsonConvert.DeserializeObject<Activity>(json);
switch (activity.type)
try
{
case "Follow":
return JsonConvert.DeserializeObject<ActivityFollow>(json);
case "Undo":
var a = JsonConvert.DeserializeObject<ActivityUndo>(json);
if(a.apObject.type == "Follow")
return JsonConvert.DeserializeObject<ActivityUndoFollow>(json);
break;
case "Accept":
var accept = JsonConvert.DeserializeObject<ActivityAccept>(json);
//var acceptType = JsonConvert.DeserializeObject<Activity>(accept.apObject);
switch ((accept.apObject as dynamic).type.ToString())
{
case "Follow":
var acceptFollow = new ActivityAcceptFollow()
{
type = accept.type,
id = accept.id,
actor = accept.actor,
context = accept.context,
apObject = new ActivityFollow()
var activity = JsonConvert.DeserializeObject<Activity>(json);
switch (activity.type)
{
case "Follow":
return JsonConvert.DeserializeObject<ActivityFollow>(json);
case "Undo":
var a = JsonConvert.DeserializeObject<ActivityUndo>(json);
if(a.apObject.type == "Follow")
return JsonConvert.DeserializeObject<ActivityUndoFollow>(json);
break;
case "Accept":
var accept = JsonConvert.DeserializeObject<ActivityAccept>(json);
//var acceptType = JsonConvert.DeserializeObject<Activity>(accept.apObject);
switch ((accept.apObject as dynamic).type.ToString())
{
case "Follow":
var acceptFollow = new ActivityAcceptFollow()
{
id = (accept.apObject as dynamic).id?.ToString(),
type = (accept.apObject as dynamic).type?.ToString(),
actor = (accept.apObject as dynamic).actor?.ToString(),
context = (accept.apObject as dynamic).context?.ToString(),
apObject = (accept.apObject as dynamic).@object?.ToString()
}
};
return acceptFollow;
break;
}
break;
type = accept.type,
id = accept.id,
actor = accept.actor,
context = accept.context,
apObject = new ActivityFollow()
{
id = (accept.apObject as dynamic).id?.ToString(),
type = (accept.apObject as dynamic).type?.ToString(),
actor = (accept.apObject as dynamic).actor?.ToString(),
context = (accept.apObject as dynamic).context?.ToString(),
apObject = (accept.apObject as dynamic).@object?.ToString()
}
};
return acceptFollow;
break;
}
break;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
return null;