changeset 2787:ad2c32082653

Fix OrthancPluginHttpClient() to return the HTTP status on errors
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Jul 2018 10:33:36 +0200
parents e7a10626645f
children 959bd8857eb5
files Core/HttpClient.cpp Core/HttpClient.h NEWS Plugins/Engine/OrthancPlugins.cpp
diffstat 4 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpClient.cpp	Wed Jul 25 13:15:11 2018 +0200
+++ b/Core/HttpClient.cpp	Thu Jul 26 10:33:36 2018 +0200
@@ -184,7 +184,7 @@
   };
 
 
-  static void ThrowException(HttpStatus status)
+  void HttpClient::ThrowException(HttpStatus status)
   {
     switch (status)
     {
--- a/Core/HttpClient.h	Wed Jul 25 13:15:11 2018 +0200
+++ b/Core/HttpClient.h	Thu Jul 26 10:33:36 2018 +0200
@@ -288,5 +288,7 @@
 
     void ApplyAndThrowException(Json::Value& answerBody,
                                 HttpHeaders& answerHeaders);
+
+    static void ThrowException(HttpStatus status);
   };
 }
--- a/NEWS	Wed Jul 25 13:15:11 2018 +0200
+++ b/NEWS	Thu Jul 26 10:33:36 2018 +0200
@@ -2,6 +2,7 @@
 ===============================
 
 * Fix incoming DICOM C-Store filtering for JPEG-LS transfer syntaxes
+* Fix OrthancPluginHttpClient() to return the HTTP status on errors
 
 
 Version 1.4.1 (2018-07-17)
--- a/Plugins/Engine/OrthancPlugins.cpp	Wed Jul 25 13:15:11 2018 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Thu Jul 26 10:33:36 2018 +0200
@@ -1865,11 +1865,16 @@
     std::string body;
     HttpClient::HttpHeaders headers;
 
-    client.ApplyAndThrowException(body, headers);
+    bool success = client.Apply(body, headers);
 
     // The HTTP request has succeeded
     *p.httpStatus = static_cast<uint16_t>(client.GetLastStatus());
 
+    if (!success)
+    {
+      HttpClient::ThrowException(client.GetLastStatus());
+    }
+
     // Copy the HTTP headers of the answer, if the plugin requested them
     if (p.answerHeaders != NULL)
     {