changeset 4244:416c35da7d25

robustness against non-dicom files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 10 Oct 2020 10:38:45 +0200
parents 64f57c9d5f79
children c70df925151e
files OrthancServer/Sources/OrthancWebDav.cpp
diffstat 1 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Fri Oct 09 18:10:24 2020 +0200
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Sat Oct 10 10:38:45 2020 +0200
@@ -1226,17 +1226,28 @@
       // instance.SetOrigin(DicomInstanceOrigin_WebDav);   // TODO
       instance.SetBuffer(content.c_str(), content.size());
 
-      std::string publicId;
-      StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default);
-      if (status == StoreStatus_Success ||
-          status == StoreStatus_AlreadyStored)
+      bool success = false;
+
+      try
       {
-        LOG(INFO) << "Successfully imported DICOM instance from WebDAV: " << path << " (Orthanc ID: " << publicId << ")";
-        uploads_.DeleteItem(uri);
+        std::string publicId;
+        StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default);
+        if (status == StoreStatus_Success ||
+            status == StoreStatus_AlreadyStored)
+        {
+          LOG(INFO) << "Successfully imported DICOM instance from WebDAV: " << path << " (Orthanc ID: " << publicId << ")";
+          success = true;
+        }
       }
-      else
+      catch (OrthancException& e)
       {
-        LOG(WARNING) << "Cannot import DICOM instance from WebWAV: " << path;
+      }
+
+      uploads_.DeleteItem(uri);
+
+      if (!success)
+      {
+        LOG(WARNING) << "Cannot import DICOM instance from WebWAV (maybe not a DICOM file): " << path;
       }
     }
   }