From f2ec034d8172850d7ccf0615fa6ab7a985bb43c0 Mon Sep 17 00:00:00 2001
From: Jon Van Oast <jon@wildme.org>
Date: Fri, 16 Feb 2024 16:14:42 -0700
Subject: [PATCH] gracefully handle case where open().write() fails

---
 app/modules/sightings/models.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/app/modules/sightings/models.py b/app/modules/sightings/models.py
index c8833dd03..423f9a020 100644
--- a/app/modules/sightings/models.py
+++ b/app/modules/sightings/models.py
@@ -1649,7 +1649,10 @@ def _heatmap_src(cls, extern_ref, q_annot_content_uuid, d_annot_content_uuid):
                 log.error(
                     f'non-image on fetching {sage_src} to {filepath}; contents in {filepath}.err'
                 )
-                open(filepath + '.err', 'wb').write(resp.content)
+                try:
+                    open(filepath + '.err', 'wb').write(resp.content)
+                except Exception as ex:
+                    log.error(f'writing {filepath}.err got error {str(ex)}')
                 return
             try:
                 resp.raise_for_status()