Skip to content

Commit

Permalink
Merge pull request #181 from snikket-im/feature/handle-invalid-avatar…
Browse files Browse the repository at this point in the history
…s-gracefully

Handle broken/incorrect avatar metadata gracefully
  • Loading branch information
mwild1 authored Mar 11, 2024
2 parents bda0f52 + 7ffcd76 commit a13fbd8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions snikket_web/prosodyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def from_api_response(
roles.extend(data.get("secondary_roles", []))
except KeyError:
roles = data.get("roles")
avatar_info: typing.List[AvatarMetadata] = []
for avatar in data.get("avatar_info", []):
# Ignore somehow broken avatars.
try:
avatar_metadata = AvatarMetadata.from_api_response(avatar)
except KeyError:
pass
avatar_info.append(avatar_metadata)
return cls(
localpart=data["username"],
display_name=data.get("display_name") or None,
Expand All @@ -131,10 +139,7 @@ def from_api_response(
deletion_request=UserDeletionRequestInfo.from_api_response(
data.get("deletion_request")
),
avatar_info=[
AvatarMetadata.from_api_response(avatar_info)
for avatar_info in data.get("avatar_info", [])
],
avatar_info=avatar_info,
)


Expand Down

0 comments on commit a13fbd8

Please sign in to comment.