From d08324e1590df4a7da19b70430e4abe364850d9b Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 17 Dec 2022 15:00:50 -0700 Subject: Handle timeouts on image fetch --- activities/models/emoji.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'activities') 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 -- cgit v1.2.3