From 45e6b362608dda47c6881b6858714bf1e2bb0760 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 29 May 2024 19:02:19 +0200 Subject: [PATCH] feat: enhance icon loading robustness Improved the `icon` function to handle attribute errors gracefully by falling back to an alternative reading method. This change addresses potential situations where the `file.response.file` attribute does not exist, ensuring icons are consistently loaded without causing runtime errors. The fallback method, `file.response.read()`, provides a reliable alternative for retrieving SVG files, thus enhancing the application's resilience and user experience. --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9312623..6c9a279 100644 --- a/main.py +++ b/main.py @@ -83,9 +83,13 @@ if os.environ.get("PRIVATECOFFEE_DEV"): def icon(icon_name): file = send_from_directory("assets", f"dist/icons/{icon_name}.svg") - file_content = file.response.file.read().decode("utf-8") + try: + file_content = file.response.file.read().decode("utf-8") + except AttributeError: + file_content = file.response.read().decode("utf-8") return file_content + app.add_template_filter(icon) if __name__ == "__main__":