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.
This commit is contained in:
Kumi 2024-05-29 19:02:19 +02:00
parent e77fc521bf
commit 45e6b36260
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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__":