changeset 5529:acdb8d78bf99

Whatever the SQL error that happens while inserting an instance in DB, remove the attachments that have been added to avoid orphan files
author Alain Mazy <am@osimis.io>
date Tue, 06 Feb 2024 15:32:54 +0100
parents b822dcebf9ff
children f88aaf269fda 2bce8d26db5e
files OrthancServer/Sources/ServerContext.cpp
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp	Wed Jan 31 13:49:58 2024 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Tue Feb 06 15:32:54 2024 +0100
@@ -722,15 +722,19 @@
         if (ex.GetErrorCode() == ErrorCode_DuplicateResource)
         {
           LOG(WARNING) << "Duplicate instance, deleting the attachments";
-
-          accessor.Remove(dicomInfo);
-
-          if (dicomUntilPixelData.IsValid())
-          {
-            accessor.Remove(dicomUntilPixelData);
-          }
+        }
+        else
+        {
+          LOG(ERROR) << "Unexpected error while storing an instance in DB, cancelling and deleting the attachments: " << ex.GetDetails();
         }
 
+        accessor.Remove(dicomInfo);
+
+        if (dicomUntilPixelData.IsValid())
+        {
+          accessor.Remove(dicomUntilPixelData);
+        }
+        
         throw;
       }