Gracefully handle expect, unsupported activities

This commit is contained in:
Mouse Reeve
2021-04-16 15:12:38 -07:00
parent f792dd0dac
commit caa261f4bf
3 changed files with 35 additions and 6 deletions

View File

@ -52,10 +52,14 @@ def naive_parse(activity_objects, activity_json, serializer=None):
if activity_json.get("publicKeyPem"):
# ugh
activity_json["type"] = "PublicKey"
activity_type = activity_json.get("type")
try:
activity_type = activity_json["type"]
serializer = activity_objects[activity_type]
except KeyError as e:
# we know this exists and that we can't handle it
if activity_type in ["Question"]:
return None
raise ActivitySerializerError(e)
return serializer(activity_objects=activity_objects, **activity_json)

View File

@ -16,7 +16,11 @@ class Verb(ActivityObject):
def action(self):
""" usually we just want to update and save """
self.object.to_model()
obj = self.object
# it may return None if the object is invalid in an expected way
# ie, Question type
if obj:
obj.to_model()
@dataclass(init=False)