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:
parent
e77fc521bf
commit
45e6b36260
1 changed files with 5 additions and 1 deletions
4
main.py
4
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")
|
||||
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__":
|
||||
|
|
Loading…
Reference in a new issue