changeset 1165:0561f2087cc9

Fix reporting of errors in Orthanc Explorer when sending images to peers/modalities
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Sep 2014 17:48:55 +0200
parents 0a55d8eb194e
children a921e3b5e763
files AUTHORS Core/RestApi/RestApiOutput.cpp NEWS OrthancServer/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/Scheduler/StorePeerCommand.cpp OrthancServer/Scheduler/StorePeerCommand.h OrthancServer/Scheduler/StoreScuCommand.cpp OrthancServer/Scheduler/StoreScuCommand.h OrthancServer/ServerContext.cpp
diffstat 9 files changed, 54 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/AUTHORS	Thu Sep 18 17:18:26 2014 +0200
+++ b/AUTHORS	Thu Sep 18 17:48:55 2014 +0200
@@ -8,7 +8,7 @@
 * Sebastien Jodogne <s.jodogne@gmail.com>
   Department of Medical Physics, CHU of Liege, Belgium
 
-  Overall design and main developper.
+  Overall design and lead developer.
 
 
 Client library
--- a/Core/RestApi/RestApiOutput.cpp	Thu Sep 18 17:18:26 2014 +0200
+++ b/Core/RestApi/RestApiOutput.cpp	Thu Sep 18 17:48:55 2014 +0200
@@ -129,6 +129,7 @@
   void RestApiOutput::SignalError(HttpStatus status)
   {
     if (status != HttpStatus_403_Forbidden &&
+        status != HttpStatus_500_InternalServerError &&
         status != HttpStatus_415_UnsupportedMediaType)
     {
       throw OrthancException("This HTTP status is not allowed in a REST API");
--- a/NEWS	Thu Sep 18 17:18:26 2014 +0200
+++ b/NEWS	Thu Sep 18 17:48:55 2014 +0200
@@ -2,6 +2,7 @@
 ===============================
 
 * Configuration/Lua to select the accepted C-Store SCP transfer syntaxes
+* Fix reporting of errors in Orthanc Explorer when sending images to peers/modalities
 * Installation of plugin SDK in CMake
 
 
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Sep 18 17:18:26 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Sep 18 17:48:55 2014 +0200
@@ -80,12 +80,17 @@
     {
       if (locker.GetConnection().Echo())
       {
+        // Echo has succeeded
         call.GetOutput().AnswerBuffer("{}", "application/json");
+        return;
       }
     }
     catch (OrthancException&)
     {
     }
+
+    // Echo has failed
+    call.GetOutput().SignalError(HttpStatus_500_InternalServerError);
   }
 
 
@@ -357,13 +362,20 @@
     for (std::list<std::string>::const_iterator 
            it = instances.begin(); it != instances.end(); ++it)
     {
-      job.AddCommand(new StoreScuCommand(context, p)).AddInput(*it);
+      job.AddCommand(new StoreScuCommand(context, p, false)).AddInput(*it);
     }
 
     job.SetDescription("HTTP request: Store-SCU to peer \"" + remote + "\"");
-    context.GetScheduler().SubmitAndWait(job);
 
-    call.GetOutput().AnswerBuffer("{}", "application/json");
+    if (context.GetScheduler().SubmitAndWait(job))
+    {
+      // Success
+      call.GetOutput().AnswerBuffer("{}", "application/json");
+    }
+    else
+    {
+      call.GetOutput().SignalError(HttpStatus_500_InternalServerError);
+    }
   }
 
 
@@ -421,13 +433,20 @@
     for (std::list<std::string>::const_iterator 
            it = instances.begin(); it != instances.end(); ++it)
     {
-      job.AddCommand(new StorePeerCommand(context, peer)).AddInput(*it);
+      job.AddCommand(new StorePeerCommand(context, peer, false)).AddInput(*it);
     }
 
     job.SetDescription("HTTP request: POST to peer \"" + remote + "\"");
-    context.GetScheduler().SubmitAndWait(job);
 
-    call.GetOutput().AnswerBuffer("{}", "application/json");
+    if (context.GetScheduler().SubmitAndWait(job))
+    {
+      // Success
+      call.GetOutput().AnswerBuffer("{}", "application/json");
+    }
+    else
+    {
+      call.GetOutput().SignalError(HttpStatus_500_InternalServerError);
+    }
   }
 
 
--- a/OrthancServer/Scheduler/StorePeerCommand.cpp	Thu Sep 18 17:18:26 2014 +0200
+++ b/OrthancServer/Scheduler/StorePeerCommand.cpp	Thu Sep 18 17:48:55 2014 +0200
@@ -39,9 +39,11 @@
 namespace Orthanc
 {
   StorePeerCommand::StorePeerCommand(ServerContext& context,
-                                     const OrthancPeerParameters& peer) : 
+                                     const OrthancPeerParameters& peer,
+                                     bool ignoreExceptions) : 
     context_(context),
-    peer_(peer)
+    peer_(peer),
+    ignoreExceptions_(ignoreExceptions)
   {
   }
 
@@ -84,6 +86,11 @@
       {
         LOG(ERROR) << "Unable to forward to an Orthanc peer in a Lua script (instance " 
                    << *it << ", peer " << peer_.GetUrl() << "): " << e.What();
+
+        if (!ignoreExceptions_)
+        {
+          throw;
+        }
       }
     }
 
--- a/OrthancServer/Scheduler/StorePeerCommand.h	Thu Sep 18 17:18:26 2014 +0200
+++ b/OrthancServer/Scheduler/StorePeerCommand.h	Thu Sep 18 17:48:55 2014 +0200
@@ -43,10 +43,12 @@
   private:
     ServerContext& context_;
     OrthancPeerParameters peer_;
+    bool ignoreExceptions_;
 
   public:
     StorePeerCommand(ServerContext& context,
-                     const OrthancPeerParameters& peer);
+                     const OrthancPeerParameters& peer,
+                     bool ignoreExceptions);
     
     virtual bool Apply(ListOfStrings& outputs,
                        const ListOfStrings& inputs);
--- a/OrthancServer/Scheduler/StoreScuCommand.cpp	Thu Sep 18 17:18:26 2014 +0200
+++ b/OrthancServer/Scheduler/StoreScuCommand.cpp	Thu Sep 18 17:48:55 2014 +0200
@@ -37,9 +37,11 @@
 namespace Orthanc
 {
   StoreScuCommand::StoreScuCommand(ServerContext& context,
-                                 const RemoteModalityParameters& modality) : 
+                                   const RemoteModalityParameters& modality,
+                                   bool ignoreExceptions) : 
     context_(context),
-    modality_(modality)
+    modality_(modality),
+    ignoreExceptions_(ignoreExceptions)
   {
   }
 
@@ -69,6 +71,11 @@
         // powered off)
         LOG(ERROR) << "Unable to forward to a modality in a Lua script (instance " 
                    << *it << "): " << e.What();
+
+        if (!ignoreExceptions_)
+        {
+          throw;
+        }
       }
     }
 
--- a/OrthancServer/Scheduler/StoreScuCommand.h	Thu Sep 18 17:18:26 2014 +0200
+++ b/OrthancServer/Scheduler/StoreScuCommand.h	Thu Sep 18 17:48:55 2014 +0200
@@ -42,10 +42,12 @@
   private:
     ServerContext& context_;
     RemoteModalityParameters modality_;
+    bool ignoreExceptions_;
 
   public:
     StoreScuCommand(ServerContext& context,
-                   const RemoteModalityParameters& modality);
+                    const RemoteModalityParameters& modality,
+                    bool ignoreExceptions);
 
     virtual bool Apply(ListOfStrings& outputs,
                        const ListOfStrings& inputs);
--- a/OrthancServer/ServerContext.cpp	Thu Sep 18 17:18:26 2014 +0200
+++ b/OrthancServer/ServerContext.cpp	Thu Sep 18 17:48:55 2014 +0200
@@ -138,7 +138,7 @@
       std::string modality = parameters["Modality"].asString();
       LOG(INFO) << "Lua script to send instance " << parameters["Instance"].asString()
                 << " to modality " << modality << " using Store-SCU";
-      return new StoreScuCommand(context, Configuration::GetModalityUsingSymbolicName(modality));
+      return new StoreScuCommand(context, Configuration::GetModalityUsingSymbolicName(modality), true);
     }
 
     if (operation == "store-peer")
@@ -149,7 +149,7 @@
 
       OrthancPeerParameters parameters;
       Configuration::GetOrthancPeer(parameters, peer);
-      return new StorePeerCommand(context, parameters);
+      return new StorePeerCommand(context, parameters, true);
     }
 
     if (operation == "modify")