Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Prevent thumbnail timeout #756

Merged
merged 3 commits into from
Jun 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions api/catalog/api/views/media_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -170,7 +171,7 @@ def _thumbnail_proxy_comm(
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")
Expand All @@ -180,8 +181,12 @@ def _thumbnail_proxy_comm(
)

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice for debugging in the future :)

f"Failed to render thumbnail due to unidentified exception: {exc}"
)

@staticmethod
def _get_proxied_image(
Expand Down