From 67b61100874d880d3309b158bd896fa8de20633c Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 11 Oct 2023 11:02:20 -0600 Subject: [PATCH] Display an empty img if a site icon can't be found This improves the search result icon feature by "hiding" the site's icon if one was not found. This happens in scenarios where a site doesn't have a /favicon.ico due to having a unique path or using javascript to load the icon. --- app/routes.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 5586a30..3d18c4a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -490,7 +490,13 @@ def element(): return send_file(io.BytesIO(empty_gif), mimetype='image/gif') try: - file_data = g.user_request.send(base_url=src_url).content + response = g.user_request.send(base_url=src_url) + + # Display an empty gif if the requested element couldn't be retrieved + if response.status_code != 200: + return send_file(io.BytesIO(empty_gif), mimetype='image/gif') + + file_data = response.content tmp_mem = io.BytesIO() tmp_mem.write(file_data) tmp_mem.seek(0)