summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-17 15:00:50 -0700
committerAndrew Godwin2022-12-17 15:00:50 -0700
commitd08324e1590df4a7da19b70430e4abe364850d9b (patch)
treefd29564d771dd86f55bf5e944e8b3997a78f7ff8
parent64f113dd8d102282da8f013ab2acf6e1c24a5934 (diff)
downloadtakahe-d08324e1590df4a7da19b70430e4abe364850d9b.tar.gz
takahe-d08324e1590df4a7da19b70430e4abe364850d9b.tar.bz2
takahe-d08324e1590df4a7da19b70430e4abe364850d9b.zip
Handle timeouts on image fetch
-rw-r--r--activities/models/emoji.py14
-rw-r--r--users/models/identity.py14
2 files changed, 18 insertions, 10 deletions
diff --git a/activities/models/emoji.py b/activities/models/emoji.py
index 441be22..522cbc2 100644
--- a/activities/models/emoji.py
+++ b/activities/models/emoji.py
@@ -2,6 +2,7 @@ import re
from functools import partial
from typing import ClassVar, cast
+import httpx
import urlman
from asgiref.sync import sync_to_async
from django.conf import settings
@@ -30,11 +31,14 @@ class EmojiStates(StateGraph):
Fetches remote emoji and uploads to file for local caching
"""
if instance.remote_url and not instance.file:
- file, mimetype = await get_remote_file(
- instance.remote_url,
- timeout=settings.SETUP.REMOTE_TIMEOUT,
- max_size=settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB * 1024,
- )
+ try:
+ file, mimetype = await get_remote_file(
+ instance.remote_url,
+ timeout=settings.SETUP.REMOTE_TIMEOUT,
+ max_size=settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB * 1024,
+ )
+ except httpx.RequestError:
+ return
if file:
instance.file = file
instance.mimetype = mimetype
diff --git a/users/models/identity.py b/users/models/identity.py
index c8a154c..afec0e7 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -46,11 +46,15 @@ class IdentityStates(StateGraph):
if await identity.fetch_actor():
# Also stash their icon if we can
if identity.icon_uri:
- file, mimetype = await get_remote_file(
- identity.icon_uri,
- timeout=settings.SETUP.REMOTE_TIMEOUT,
- max_size=settings.SETUP.AVATAR_MAX_IMAGE_FILESIZE_KB * 1024,
- )
+ try:
+ file, mimetype = await get_remote_file(
+ identity.icon_uri,
+ timeout=settings.SETUP.REMOTE_TIMEOUT,
+ max_size=settings.SETUP.AVATAR_MAX_IMAGE_FILESIZE_KB * 1024,
+ )
+ except httpx.RequestError:
+ # We've still got enough info to consider ourselves updated
+ return cls.updated
if file:
identity.icon = file
await sync_to_async(identity.save)()