Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Prevent thumbnail timeout (#756)

Dhruv Bhanushalib114de9d4bf6
diff --git a/api/catalog/api/views/media_views.py b/api/catalog/api/views/media_views.py
index d01005299..3e61202f0 100644
--- a/api/catalog/api/views/media_views.py
+++ b/api/catalog/api/views/media_views.py
@@ -1,5 +1,6 @@
import json
import logging as log
+from http.client import RemoteDisconnected
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import Request, urlopen
@@ -172,7 +173,7 @@ class MediaViewSet(ReadOnlyModelViewSet):
req = Request(upstream_url)
for key, val in headers:
req.add_header(key, val)
- upstream_response = urlopen(req, timeout=5)
+ upstream_response = urlopen(req, timeout=10)
res_status = upstream_response.status
content_type = upstream_response.headers.get("Content-Type")
@@ -182,8 +183,12 @@ class MediaViewSet(ReadOnlyModelViewSet):
)
return upstream_response, res_status, content_type
- except HTTPError as exc:
+ except (HTTPError, RemoteDisconnected, TimeoutError) as exc:
raise get_api_exception(f"Failed to render thumbnail: {exc}")
+ except Exception as exc:
+ raise get_api_exception(
+ f"Failed to render thumbnail due to unidentified exception: {exc}"
+ )
@staticmethod
def _get_proxied_image(